I had similar symptoms, but my problem was that I was nesting BrowserRouter
Do not nest BrowserRouter
, because the history
object will refer to the nearest BrowserRouter
parent. So when you do a history.push(targeturl)
and that targeturl it's not in that particular BrowserRouter
it won't match any of it's route, so it will not load any sub-component.
Nest the Switch
without wrapping it with a BrowserRouter
App.js
file<BrowserRouter>
<Switch>
<Route exact path="/nestedrouter" component={NestedRouter} />
<Route exact path="/target" component={Target} />
</Switch>
</BrowserRouter>
NestedRouter.js
file<BrowserRouter>
<Switch>
<Route exact path="/nestedrouter/" component={NestedRouter} />
<Route exact path="/nestedrouter/subroute" component={SubRoute} />
</Switch>
</BrowserRouter>
BrowserRouter
from NestedRouter.js
file <Switch>
<Route exact path="/nestedrouter/" component={NestedRouter} />
<Route exact path="/nestedrouter/subroute" component={SubRoute} />
</Switch>