react-router: react-router-redux Redirects no longer trigger an action to the reducer
Version
react-router-redux@5.0.0-alpha.7 & react-router-redux@5.0.0-alpha.8
Summary
Redirects in a route nolonger trigger an action to the reducer.
Steps to reproduce
My routes setup.
const Routes = ({store}) => (
<CoreLayout>
<Switch>
<Route exact={true} path='/' render={Routes.homeRedirect} />
<Route path='/photos/:folder*' component={PhotoView} />
</Switch>
</CoreLayout>
)
Routes.homeRedirect = () => (
<Redirect to='/photos' />
)
Expected Behavior
In version alpha.6 both the initial page load and the redirect are sent to the reducer.
{
type: '@@router/LOCATION_CHANGE',
payload: {
pathname: '/',
search: '',
hash: ''
}
}
{
type: '@@router/LOCATION_CHANGE',
payload: {
pathname: '/photos',
search: '',
hash: '',
key: 'mswocw'
}
}
Actual Behavior
With version alpha.7 and 8 the only initial page load is sent to the reducer
{
type: '@@router/LOCATION_CHANGE',
payload: {
pathname: '/',
search: '',
hash: ''
}
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 16
- Comments: 21 (3 by maintainers)
Experiencing this issue as well.
Connected Router beings listening to history in componentDidMount and react-router Redirect performs the history push in componentDidMount as well. Because componentDidMount is called on children before the parent, there is a moment where a Redirect pushes a new history but the Connected Router is not yet listening to history.
Alpha 9 is up. We’ll get this right at some point…
Downgrading to alpha.6 did fix the issue for me.
For those who it did not work for, just ensure you don’t have your version set to still grab alpha.8, in your package.json,
"react-router-redux": "5.0.0-alpha.6"instead of"react-router-redux": "^5.0.0-alpha.6"(not the ^)The same issue in 5.0.0-alpha.7 and 5.0.0-alpha.8.
Or moving this.handleLocationChange(history.location); to componentDidMount
I removed BrowserRouter from ConnectedRouter and dispatch works well again! Maybe it will helps somebody.
I have the similiar problem. In my case, action
@@router/LOCATION_CHANGEtriggered twice with different pathname in wrong order: first, with pathname that is equals toRedirect toproperty, and then with pathname that equalsRedirect fromproperty. So reducer receives wrong last location. P.S. i using React 16 and alpha.8 version of react-router-redux. Maybe this problem caused by new React version?I know I had a look look through the commits to see if I could pinpoint the problem.
If I downgrade to alpha.6 then I get the expected result, upgrading results in the problem surfacing again.
I’ll try to put together an example tonight to reproduce the problem.