如何在保留初始查询参数的同时使用 react-router 重定向? [英] How to redirect with react-router while preserving initial query parameters?
问题描述
在我的路线中,我有
<Redirect from="/" to="/view/something"/>...</路线>
但是如果我使用 rooturl/?query=somequery
访问根 url,我会在重定向后丢失查询参数.重定向后如何保留所有查询参数?
希望能帮到你:https://github.com/rackt/react-router/issues/1034
在这里,您可以在重定向后指定和重用现有的查询参数,如下所示:
<Redirect from="/foo/:id" to="/bar/:id"/>
(id
将被重用).>
此外,您可能希望在过渡之前/之后有一些钩子,实际上是为了某种路由管理.可以使用 onEnter
和 onLeave
钩子.您可以在官方 文档.
In my routes I have
<Route>
<Redirect from="/" to="/view/something"/>
...
</Route>
But if I hit the root url with rooturl/?query=somequery
I lose the query paremeter after the redirect. How can I preserve all query parameters after redirect?
I hope it will help: https://github.com/rackt/react-router/issues/1034
Here you can specify and reuse your existing query params after redirect like this:
<Redirect from="/foo/:id" to="/bar/:id"/>
(id
will be reused).
Also you might want to have some hooks right before/after transition is actually done for some kind of routing management. It's possible to do with onEnter
and onLeave
hooks. You can read about it in official docs.
这篇关于如何在保留初始查询参数的同时使用 react-router 重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!