React-router: Routes and Switch do not rerender on location update it parent component does not rerender

Created on 14 Jun 2017  路  3Comments  路  Source: ReactTraining/react-router

React-router version : 4..1.1
This is a problem to get an optimized application when only some part of the app depend on the location, as this means the a major part need to be rerendered for nothing. I know it is a well known problem of react context, and therefore not specific to react-router.

There seem to be a solution to such a problem explained on this medium blog post: medium. This solution is given on React's website as a possibility to fix the issue.

Basically, the idea is to have Route, Switch and Redirect components subscribe to an change of location context, and rerender them using setState.
I will try such a solution by wrapping Route and Switch so that the subscribe to location update and see how this behaves in real life application.

Most helpful comment

@timdorr
Thanks for reading me and writing such a long answer, but the link you gave just tells 'pass down the location/match objects as props, it will rerender'. Well, that'show React works.
Having to do such is really disappointing when you are used to react-redux, and used to rerendering only the required components.
Route and Switch are expected, on a developper's point of view, to rerender on location change (if matching), without needing to rerender the parent component. As I explained in the initial issue, on normal apps, it is not expected to rerender the full app on each user action.

All 3 comments

Thanks for providing <Switch> @ReactRouter4Team
It solved a lot of problems for our project.

@timdorr
Thanks for reading me and writing such a long answer, but the link you gave just tells 'pass down the location/match objects as props, it will rerender'. Well, that'show React works.
Having to do such is really disappointing when you are used to react-redux, and used to rerendering only the required components.
Route and Switch are expected, on a developper's point of view, to rerender on location change (if matching), without needing to rerender the parent component. As I explained in the initial issue, on normal apps, it is not expected to rerender the full app on each user action.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewpillar picture andrewpillar  路  3Comments

stnwk picture stnwk  路  3Comments

nicolashery picture nicolashery  路  3Comments

ackvf picture ackvf  路  3Comments

yormi picture yormi  路  3Comments