我正在使用 next
React Router 版本,它似乎正在删除参数。我希望下面的重定向保留 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>
这看起来像是一个 已解决的问题,但它不起作用。还有什么我需要传递给 to
路线吗?
原文由 Matt Norris 发布,翻译遵循 CC BY-SA 4.0 许可协议
这是我一直在使用的,类似于其他答案但没有依赖性: