我使用的是React Router的next版本,它似乎正在删除参数。我希望下面的重定向保留channelId的值,但是to路由在路径中使用文字字符串":channelId“。
<Switch>
<Route exact path="/" component={Landing} />
<Route path="/channels/:channelId/modes/:modeId" component={Window} />
<Redirect
from="/channels/:channelId"
to="/channels/:channelId/modes/window" />
</Switch>这看起来像resolved issue,但它不工作。是否还有其他东西需要传递到to路由?
发布于 2017-11-27 21:16:45
我这样做了,它起作用了:
<switch>
<Route path={`/anypath/:id`} component={Anycomponent} />
<Route
exact
path="/requestedpath/:id"
render={({ match }) => {
if (!Auth.loggedIn()) {
return <Redirect to={`/signin`} />;
} else {
return <Redirect to={`/anypath/${match.params.id}`} />;
}
}}
/>
</switch>
https://stackoverflow.com/questions/43399740
复制相似问题