Is there a way to get React Router to open a link in new tab? I tried this and it did not work.
I think Link component does not have the props for it.
You can have alternative way by create a tag and use the makeHref method of Navigation mixin to create your url
<a target='_blank' href={this.makeHref(routeConsts.CHECK_DOMAIN, {},
{ realm: userStore.getState().realms[0].name })}>
Share this link to your webmaster
</a>
For external link simply use an achor in place of Link:
<a rel="noopener noreferrer" href="http://url.com" target="_blank">Link Here</a>
The simples way is to use 'to' property:
<Link to="chart" target="_blank" to="http://link2external.page.com" >Test</Link>
In React Router version 5.0.1 and above, you can use:
<Link to="route" target="_blank" onClick={(event) => {event.preventDefault(); window.open(this.makeHref("route"));}} />
You can use "{}" for the target, then jsx will not cry
<Link target={"_blank"} to="your-link">Your Link</Link>
To open an url in a new tab, you can use the Link tag as below:
<Link to="/yourRoute" target="_blank">
Open YourRoute in a new tab
</Link>
It's nice to keep in mind that the <Link>
element gets translated to an <a>
element, and as per react-router-dom docs, you can pass any props you'd like to be on it such as title, id, className, etc.