useParams
返回 URL 参数的键/值对的对象。使用它来访问当前
function Home() {
let { path } = useParams<any>();
return <h2>Path {path}</h2>;
}
function App() {
return (
<div style={{
width: '400px',
margin: '20px auto'
}}>
<Router>
<Switch>
<Route path="/:path">
<Home></Home>
</Route>
</Switch>
</Router>
</div>
);
}
参考资料
https://reactrouter.com/web/example/url-params
https://blog.csdn.net/weixin_43870742/article/details/102966040