So, I have a few routes set up in this fashion:
index.js
<Route exact path={pathDefault} component={Home}>
<Route path={path1} component={component1}/>
<Route path={path2} component={component2}/>
</Route>
component1.js
<Route exact path={`${props.match.url}`} component={Summary}/>
<Route path={`${props.match.url}`/someOtherPath1} component={SubComponent1}/>
<Route path={`${props.match.url}`/someOtherPath2} component={SubComponent2}/>
component2.js is set up similarly.
The idea here is that I have multiple top-level routes, which have default pages. But, then sub-routes that can be switched between. This works ok, until, when at one of the sub-level routes like component1/someOtherPath2 I can switch between someOtherPath1 and someOtherPath2, but if I then try to change one of the top level routes using history.push(path2), instead of going back to a top level component (i.e. path1's default component), it ends up pushing a compounded, and thus incorrect route, like component1/component2.
So, how would you change a higher-level route when in a lower level component programmatically (preferably using history.push or similar)?
history.pushas long as you import history from whenever you inject it into your react-router. Once you import this into your component you can just usehistory.pushlike normal. Let me know if you get stuck and I'll create a sandbox for you.<BrowserHistory>?withRouteron the components to get history on the props.