Skip to content Skip to sidebar Skip to footer

Auth Route ComponentWillMount Or DidMount Did Not Trigger When Navigate?

I have a component as 'middleware' where it check for condition and trigger some function, it work when user enter into the page (I mean initial load) or user refreshed the page. B

Solution 1:

Because componentWillMount and componentDidMount are the mounting methods, not updating methods, they will not get called on component re-rendering.

Answer :

You need to do one change, put the BrowserRouter here:

render(<BrowserRouter><App /></BrowserRouter>, document.getElementById('root'));

And use componentWillReceiveProps inside Auth component, for initial rendering componentDidMount will get called and for each route change componentWillReceiveProps will get called, you can execute the function at both the places.

Working Code.


Post a Comment for "Auth Route ComponentWillMount Or DidMount Did Not Trigger When Navigate?"