Closed gallinaromaurizio closed 2 years ago
I think this should work:
function Hello() {
return (
<Routes>
<Route path=":name" element={<HelloChild/>} />
</Routes>
);
}
function HelloChild() {
const pars = useParams();
console.log(pars);
return (<div>{pars.name}</div>);
}
Correct, useParams is only for the ancestor routes, not the routes underneath that component.
What version of React Router are you using?
6.2.2
Steps to Reproduce
In Main.js :
In Hello.js
Test Case Starter:
Expected Behavior
useParams should return an object with the property name matching the name of the dynamic param :hello :
{hello: 'James'}
Actual Behavior
useParams returns an object with a wildcard character:
{*:'James'}
If I add more segments to this route I still have one wildcard prop object and the entire path along with it:
{*:'James/credit-cards/1'}