我使用的是react-router-dom:4.3.0-rc.3
。
路由组件
<Switch>
<Redirect from='/p/:userId' to='/p/:userId/main' />
<Route path="/p/:userId/main" component={Main} />
</Switch>
当我得到一个url /p/123456
时,它会重定向到/p/:userId/main
并丢失userId。
我对this.In官网感到困惑,我找不到答案。
发布于 2018-09-02 17:25:46
<Redirect>
不执行任何模式编译。您必须给它提供您想要重定向到的实际URI。
我将采用的方法是使用<Route>
而不是<Redirect>
进行匹配,然后使用解析后的param来构建重定向URI。
<Route path="/p/:userId" render={({ match }) => (
<Redirect to={`${match.url}/main`} />
)} />
https://stackoverflow.com/questions/52135463
复制相似问题