You can redirect to an external link in react router dom from Component prop of Route. As you know, you can load a component for a route by declaring it in Component prop. To redirect to an external link, we can simply put the link in window.location.href. Check out the code –

<Route path='/some-path' component={() => { 
     window.location.href = 'link_to_redirect_to'; 
     return null;

Also, you can create a temporary link and programmatically click on it –

<Route path='/some-path' component={() => { 
  var link = document.createElement('a');
  link.href = 'link_to_redirect_to';
  return null;
}} />

    Tweet this to help others

Live Demo

About the Author


I am Akash Mittal, an overall computer scientist. If you want to guest post, need help in your projects, want to advertise, Feel free to contact me at [email protected]

View All Articles