React Router Param
useParams()
in your routing page use /:xxx
function App() {
return (
<Routes>
<Route path="users">
<Route path="/profile" element={<ProfilePage />} />
<Route path="/profile/:userId" element={<ProfilePage />} />
<Route path="me" element={...} />
</Route>
</Routes>
);
}
in your page | profilepage/5
import * as React from 'react';
import { Routes, Route, useParams } from 'react-router-dom';
function ProfilePage() {
// Get the userId param from the URL.
let { userId } = useParams(); // 5
// ...
}
function runPage(){
return (<Text> {userId} </Text>)
}
Last updated
Was this helpful?