question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot navigate on `componentDidMount`

See original GitHub issue

Hi,

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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
trochcommented, Aug 13, 2018

I don’t think it is related to the lifecycle hook used. I’m going to have a look.

0reactions
trochcommented, Aug 22, 2018

6.3.0 has been released, and fix is confirmed (Don’t use 6.2.0, it had an issue).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found