gpt4 book ai didi

javascript - React Router Redirect 丢弃参数

转载 作者:可可西里 更新时间:2023-11-01 02:02:43 28 4
gpt4 key购买 nike

我正在使用 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com