Answer the question
In order to leave comments, you need to log in
Why does React render all routes?
Good afternoon. I just can't understand why all components are rendered in this format
<Route exact path="/login">
<LoginPage />
</Route>
<App>
<Route exact path="/">
<MainPage />
</Route>
<Route exact path="/categories">
<Categories />
</Route>
<Route path="/categories/add">
<CategoriesAddPage />
</Route>
<Route exact path="/settings">
<Settings />
</Route>
</App>
import routes from './routes';
ReactDOM.render(
<Provider store={createStore(reducer)}>
<Router>
<ServiceContext.Provider value={categoriesService}>
{routes}
</ServiceContext.Provider>
</Router>
</Provider>,
document.getElementById('root')
);
const routes = (
<React.Fragment>
<Route exact path="/login" component={LoginPage} />
<App>
<Route exact path="/" component={MainPage} />
<Route exact path="/categories" component={Categories} />
<Route path="/categories/add" component={CategoriesAddPage} />
<Route exact path="/settings" component={Settings} />
</App>
</React.Fragment>
)
export default routes;
const App = (props) => {
return (
<div className="app">
<div className="content">
{props.children}
</div>
<Navigation />
</div>
)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question