Let's say I access directly access from browser the URL
http://localhost:3000/developerList/developer/2
I will have a back button on the page that should go back to parent route, to
http://localhost:3000/developerList/
How can I achieve this? I can't use
history.goBack()
Because that triggers a browser back behavior, which actually goes back to google.com (assuming that's where I came from)
I also can't use
history.push('/developerList')
because that's not dynamic.
I know this can be done, froming from angular background where you can just do $state.go('^'); and it knows to remove the current route /developer/2 (yes, even the /2 part).
Any chance this can be done in react with libraries or i have to write something. For the life of me I cannot figure it out.
Here is the structure of my routings:
App.js
export class App extends React.Component {
render() {
return (
<Router>
<Route path='/developerList'>
<DeveloperListPage></DeveloperListPage>
</Route>
</Router>
);
}
}
DeveloperListPage.js
export class DeveloperListPage extends React.Component {
render() {
return (
<div className="developer-list-page">
<Route path='/developerList/developer/:id'>
<DeveloperPage></DeveloperPage>
</Route>
</div>
)
}
}
and now in DeveloperPage I wish to have a go back functionality