score:2
Accepted answer
Your <Lesson />
component only sets the lesson during the componentDidMount
lifecycle hook. If you're on a lesson and you change the slug, it does not cause the component to remount. You can use the componentWillReceiveProps
lifecycle hook to accomplish what you're after.
componentWillReceiveProps(nextProps) {
api.getLesson(nextProps.match.params.lesson)
.then((lesson) => {
this.setState({
lesson: lesson[0]
});
});
}
score:0
This issue with componentDidMount event. It's not fired when you change Lesson. So you should use componentDidUpdate to change a lesson.
componentDidUpdate() {
if (this.props.match.params.lesson !== this.state.lesson.slug)
api.getLesson(this.props.match.params.lesson)
.then((lesson) => {
this.setState({
lesson: lesson[0]
});
});
}
}
Source: stackoverflow.com
Related Query
- React router 4 `Link` component only changing the url and not updating the route
- React Router v6 Link component not changing the page at root url
- React router 4 - Why is my component only rendered on manually setting the url but not on clicking a Link with same url?
- react router link changing url but not the component
- React Router V4: How to render a modal in the same screen changing only the url and then with that url, be able to rebuild the whole screen
- React reach router link tag updates url but not the component
- React Router Link not changing URL or component
- Reactjs - changing url using react router but the component does not change
- React Router Link is not working. The Route changes but the component doesn't get rendered
- React router Link is changing the url but not actually redirecting
- React Router Link is changing URL but the component remains same
- React Router Link Not Rendering the Component but changes the URL
- How to fix React Router component not updating as route changes
- React Router - Go back to the last page visited, and not the default component
- React router is not reloading page when url matches the same route
- Why does my React app append the external URL to http://localhost:/<port> and not to ONLY the URL itself?
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- React Router v4: Component and Children in the same route
- React router redux Link changing route, but not component
- CSS not changing when using React Router to route to another component
- Link Button to route to the another component is not working in React js
- React router not reloading Component when changing url params
- React 18 router changing url but not component
- React Router: The Router only loads / path and does not load any other path
- ReactJS - React Router not changing component but url is changing
- Clicking on link changes route but not Component itself - React Hook Router
- How to link to Routes inside the component rendered by another Route with React Router
- React router is changing the URL but not loading the webpage properly
- Clicking the submit button to go to the next tab only changes the URL but not the tab and the component itself. How can I fix?
- Styling the active link using the NavLink component from React Router is not working as expected
More Query from same tag
- Access api from a CMS in Next.js
- What's wrong with my custom hook in React?
- toggle between sorted list and original list React.js
- How can handle not found page for nested routing in react router v4?
- axios post method errors react
- Displaying images with img tag in React.js
- Submenu closes improperly in React + Material UI
- React Sidebar Component Open/Close
- Problems facing whenever I add a filter function in react app
- Why is removing an item from a list with the key as index working as expected?
- Configuring next.config file
- Webpack mini-css-extract-plugin doesn't produce css files when building
- Create html in reactjs using nested for loops.
- setState to the localstorage.getItem in ReactJS
- How to render an editable table with formik 2 and react-table 7?
- Error: [Home] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>
- Reading the Data from a CSV File on Drop Event
- why key error Recursion component in React
- How to fill an svg image with specific length color
- How to use antd divider to separate two sides of the screen in a react component?
- How can I set the textfield as disabled and when typed, it will be enabled again?
- React Typescript .map is not a function error on a typed array
- TypeScript and React: Pass component in props and return it from a function
- Nested object destructuring with computed object property names - react state
- Fetching data from API - Unhandled Rejection (TypeError): Object(...) is not a function
- How to use different fonts (more than one) of react-native-vector-icons in one file?
- React conditional divs with hooks
- Microsoft Graph API auth error: "Access token validation failure. Invalid audience"
- CSS lower down/cut an edge
- Call function every time any component updates (including route change)