I'm trying to pass user_id through url as follows. The link http://localhost:3000/activate/1 works now but I have no idea where to find the params? If I recall correctly I should be able to access them from "props.match" but this doesn't exist. I can't find the params in props.
Can anyone point me in the right direction what I did wrong?
I'm using React 17.0.2
<Routes>
<Route
path={"/activate/:user_id"}
element={
<Activate />
}
/>
</Routes>
Activate.js
export default function Activate(props) {
useEffect(() => {
console.log("props", props);
console.log("props", props.match); // undefined
activate();
}, []);
return <div>hi</div>;
}
CodePudding user response:
There is a hook "useParams" in react-router-dom.
let { id } = useParams();
where "id" is your param (users/:id) You can read about that here: https://v5.reactrouter.com/web/api/Hooks/useparams