Answer the question
In order to leave comments, you need to log in
Should all components be re-rendered when following a react-router link?
Good afternoon. I have an application with the following structure:
<BrowserRouter>
<Header />
<div className="main_block">
<div className="main_block_content">
<Switch>
{routes.map((route, idx) => <Route key={idx} {...route} />)}
</Switch>
</div>
</div>
<Footer />
</BrowserRouter>
{ path: '/about', exact: true, component: PageAboutContainer }
Answer the question
In order to leave comments, you need to log in
Use React.memo for the header and footer. Or, if they are class components, inherit from PureComponent.
Regular non-memo components are always re-rendered when the parent is re-rendered.
Or, as an option, they can be moved outside the BrowserRouter, and the latter can be issued as a separate component
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question