admin管理员组文章数量:1312888
There's a ponent on '/example' route. When I navigate to that path, the ponent being rendered. The problem is that I need to ignore rendering ponent and get redirected to the external link (which happen to have the same route) - '/example'. Is there any way for me to ignore or get around react-router route?
There's a ponent on '/example' route. When I navigate to that path, the ponent being rendered. The problem is that I need to ignore rendering ponent and get redirected to the external link (which happen to have the same route) - '/example'. Is there any way for me to ignore or get around react-router route?
Share Improve this question asked Aug 20, 2019 at 10:54 nevs nevsnevs nevs 712 silver badges6 bronze badges 1-
use a
<a ...></a>
instead of<Link>
– Vaibhav Vishal Commented Aug 20, 2019 at 10:57
2 Answers
Reset to default 6Here's a one-liner for using React Router to redirect to an external link:
<Route path='/privacy-policy' ponent={() => {
window.location.href = 'https://example./1234';
return null;
}}/>
You can try using Redirect
<Route path="/example" render={() => {
return <Redirect to="//external.url/example" />
}} />
Or if you have a <Switch>
around the routes you can shorten it:
<Redirect from="/example" to="//external.url/example" />
本文标签: javascriptIgnore reactrouter routeStack Overflow
版权声明:本文标题:javascript - Ignore react-router route - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741904579a2404068.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论