In my React app, after navigating from Home to a child page and then hitting the back button, React <Router> shows a mismatched location in it's internal state vs the props it's passed from history and the incorrect <Route> is displayed for the currently shown URL in the address bar
The contents of the <Route> do change; data gets updated by the location change Redux action. The displayed <Route> shows new data, but it's the wrong <Route>.
The basic structure of the app is:
<Root> (custom)
<Provider> (react-redux)
<ConnectedRouter> (connected-react-router)
<App> (custom)
<Switch> (react-router-dom)
<Route path="/" exact /> (react-router-dom)
<Route path="/quality:q" /> (react-router-dom)
Initially we navigate to root and <Route path="/> is correctly displayed. We click a link that correctly takes us to <Route path="/quality/:q" />. From there we hit browser back, the URL changes to / but <Route path="/quality:q" /> is still displayed, but it shouldn't be anymore.
Redux devtools show this rendered tree, which I'm including a few of the key components added by those we've used explicitly.
<Root> (custom)
<Provider> (react-redux)
<ConnectedRouter> (connected-react-router)
<Router> (injected)
<Context.Provider> (injected)
<App> (custom)
<Switch> (react-router-dom)
<Route path="/" exact /> (react-router-dom)
<Route path="/quality:q" /> (react-router-dom)
When in this incorrect state, everything up to <ConnectedRouter> is correct. <ConnectedRouter> has a single prop which is history that has the correct location, the root.
The <Router> immediately below it is mismatched. It has a history prop that is ok, but it has a stale location in state that shows the old url.
When the bad location data is context passed to the <Route>s they get the path to check against from their location prop which match's <Router>'s stale state. As a result, the wrong <Route> is rendered.
I can't figure out what I did to cause this mismatch. It's all straightforward routes and uses <Link> components for all links from home to the child pages and back.
Has anyone seen this before and/or can point me in the direction as how to resolve this problem?
