4

There's a component on '/example' route. When I navigate to that path, the component being rendered. The problem is that I need to ignore rendering component 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?

1
  • use a <a ...></a> instead of <Link> Commented Aug 20, 2019 at 10:57

2 Answers 2

6

Here's a one-liner for using React Router to redirect to an external link:

<Route path='/privacy-policy' component={() => { 
     window.location.href = 'https://example.com/1234'; 
     return null;
}}/>
Sign up to request clarification or add additional context in comments.

1 Comment

Using React, and implementing multiple sso providers configured via Spring Security 5, This was a working solution i could find to get around reactRouter and hit my backend oauth2 endpoints. thanks for the info!
1

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" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.