我正在使用 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
路线吗?
最佳答案
这是我一直在使用的,类似于其他答案但没有依赖性:
<Route
exact
path="/:id"
render={props => (
<Redirect to={`foo/${props.match.params.id}/bar`} />;
)}
/>
关于javascript - React Router Redirect 丢弃参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43399740/