I am trying to drive my application's navigation from its state. Here's my use case:
Given the user is on the Login page
When the application state changes to isLoggedIn
Then the application should navigate to the Dashboard page
Here's my current implementation which works:
if (browserHistory.getCurrentLocation().pathname === '/login' && store.isLoggedIn) {
browserHistory.push('/dashboard');
}
Unfortunately going through react-router docs and issues, I understand that browserHistory.getCurrentLocation()
is not an official API and it should not be used. Is there a recommended way to do this?
P.S. This code is running outside a React component, so I cannot use this.props.location.pathname