我有这样的东西...
const WrappedHeader = withRouter((props)=><Header {...props}/>);
const AppTemplate = (
<ThemeProvider theme={LIGHT_THEME}>
<div style={wrapper}>
<WrappedHeader />
<Route exact path="/" component={Home}/>
<Route path="/Something/:id?" component={Something}/>
...
</div>
</ThemeProvider>
)
运行此命令时,我在Route中有以下代码...
const id = useRef(useParams().id);
这很好用,但是当我尝试添加类似于标题的内容时,我将无法使用useParams
。当我尝试使用props.match时,似乎匹配了错误的路线。如何从路线外的元素获取参数?
props.match == {path: "/", url: "/", params: {…}, isExact: false}
props.location == {pathname: "/Something/123", search: "", hash: "", state: undefined}