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
Add a ment  | 

2 Answers 2

Reset to default 6

Here'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