Is there a way to get React Router to open a link in new tab? I tried this and it did not work.
<Link to="chart" target="_blank" query={{test: this.props.test}} >Test</Link>
It's possible to fluff it by adding something like onClick="foo"
to the Link like what I have above, but there would be a console error.
Thanks.
To open a link in a new tab in React, use the <a> element and set its target prop to _blank , e.g. <a href="https://google.com" target="_blank" rel="noopener noreferrer"></a> . The _blank value means that the resource is loaded into a new tab.
Use the window. location. replace() method to redirect to an external url in React, e.g. window. location.
To set the target prop of an element to _blank in React, use an anchor element and set the rel prop, e.g. <a href="https://example.com" target="_blank" rel="noopener noreferrer"> . The _blank value means that the resource is loaded into a new tab.
Since React Router version 5.0.1, you can use:
<Link to="route" target="_blank" rel="noopener noreferrer" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With