Cannot navigate on `componentDidMount`
See original GitHub issueHi,
I have troubles to navigate in the componentDidMount hook.
I’ve forked router5-react example, and rewrote some of the inbox component to redirect after the component have mounted
class Inbox extends React.Component {
componentDidMount() {
this.props.router.navigate('compose')
}
render() {
const { route, emails, router } = this.props
return (
<div className="inbox">
<InboxList emails={emails} />
{route.name === 'inbox.message' ? (
<Message {...emails[route.params.id]} key={route.params.id} />
) : null}
</div>
)
}
}
export default (props) => (
<RouteNode nodeName="inbox">
{({ route, router }) => <Inbox route={route} router={router} {...props} />}
</RouteNode>
)
The first time, (when we arrive on this page from the browser), the URL is correclty updated but the page content doesn’t change. The route.name is wrong whereas router.getState().name is good.
Here is the reproduction: https://stackblitz.com/edit/react-router5-new-context-api-fhgkus?file=components/Inbox.js
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
`componentDidMount()` function is not called after navigation
I have face this issue, the problem is when you navigate a page, the first time it call constructor, componentWillmount, ...
Read more >this.props.navigation.navigate in componentDidMount and ...
I have a login screen. Prior to the LoginScreen mounting, I'm checking if the user is logged in (user is passed via props)...
Read more >Navigation lifecycle
When going back from B to A, componentWillUnmount of B is called, but componentDidMount of A is not because A remained mounted the...
Read more >componentDidMount()` function is not called after navigation ...
I have face this issue, the problem is when you navigate a page, the first time it call constructor, componentWillmount, render componentDidmount, ...
Read more >componentDidMount is not invoked when navigating to a route
The thing about your components mounting / not mounting might be related to that. React router does not navigate browser, it only changes...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I don’t think it is related to the lifecycle hook used. I’m going to have a look.
6.3.0 has been released, and fix is confirmed (Don’t use 6.2.0, it had an issue).