【发布时间】:2021-05-21 17:43:29
【问题描述】:
是否可以获得当前匹配路由的路径模式?示例:
<Route
path=":state/:city*"
element={
<Page />
}
/>
// Page.jsx
function Page() {
...
// usePathPattern doesn't actually exist
const pathPattern = usePathPattern(); // pathPattern = ":state/:city*"
...
}
我知道我可以使用useMatch 来检查当前位置是否与特定路径模式匹配,但是组件必须知道路径模式是什么。
【问题讨论】:
标签: javascript reactjs react-router react-router-dom