This problem is driving me insane, I got a simple little app created by create-react-app and I am using React-Router.
JSX:
<Router>
<Route path="/pages/:pageId" component={Page} />
</Router>
In the Page component I have an fetch on componentDidMount, its working as expected first time the route is loaded.
For example I visit: /pages/13 and then it fetches that pages data, but when I am on: /pages/13 and then click on a Link component (imported from React-Router) redirecting me to: /pages/15 - the pageId prop is then updated but it never re-renders.
The Page component never run componentWillUnmount before, or componentDidMount after.
Expected behavior:
- Visit:
/pages/13→render()→componentDidMount()→render() - Click on Link component
/pages/15→componentWillUnmount()→render()→componentDidMount()→render()
I am using the following versions:
- react: 16.3.2
- react-dom: 16.3.2
- react-router-dom: 4.2.2
What am I doing wrong? I am still pretty new to React so be nice :)