13

I have the following code:

    <NavLink to="//student.lvh.me:8080/users/edit">
      <DropDownLink>Wiki</DropDownLink>
    </NavLink>

how do I get navlink to work with external URLs? I get the following error in console:

Uncaught DOMException: Failed to execute 'pushState' on 'History': A history state object with URL 'http://student.lvh.me:8080/users/edit' cannot be created in a document with origin 'http://localhost:3000' and URL 'http://localhost:3000/'.

is there a better way to handle external links?

snowflakekiller
  • 3,428
  • 6
  • 27
  • 45

2 Answers2

29

react-router meant to route in a Single Page Applications, i.e route is handled on the client side.
When you want to route to an external page e.g route is handled on the server side, you can use a normal anchor tag:

<a href="url.com">Wiki</a>
Sagiv b.g
  • 30,379
  • 9
  • 68
  • 99
4

<NavLink> is very easy to use for navigating to external url. Try this:

<NavLink to={{pathname: "https://infortts.com"}} target="_blank">
  Some Component Here
</NavLink>
rttss_sahil
  • 235
  • 4
  • 10
  • 4
    It should read `to={{pathname: "https://infortts.com"}}` instead of `to={{pathname="https://infortts.com"}}` – shlgug Nov 02 '21 at 13:47