Answer the question
In order to leave comments, you need to log in
How to rewrite such code on React Router V6?
There is such a code using the render function. In v6 react-router, these functions and component have been replaced with element . How then to rewrite this code to the new standard?
Now the console is getting an error: " Matched leaf route at location "/users/4" does not have an element. This means it will render an with a null value by default resulting in an "empty" page ."
The code:
<Route path='/users/:id' render={({match, location, history}) => {
const { id } = match.params;
return <UserDetails userId={ id } />}}/>
Answer the question
In order to leave comments, you need to log in
import { Routes, Route, useParams } from 'react-router-dom';
const UserDetailsPage = () => {
const { id } = useParams();
return <UserDetails userId={ id } />}}/>
}
<Route path='/users/:id' element={<UserDetailsPage />}/>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question