Is there a way to get React Router to open a link in new tab? I tried this and it did not work.
Starting with react_router 1.0, the props will be passed onto the anchor tag. You can directly use target="_blank"
. Discussed here: https://github.com/ReactTraining/react-router/issues/2188
We can use the following options:-
// first option is:-
<Link to="myRoute" params={myParams} target="_blank">
// second option is:-
var href = this.props.history.createHref('myRoute', myParams);
<a href={href} target="_blank">
//third option is:-
var href = '/myRoute/' + myParams.foo + '/' + myParams.bar;
<a href={href} target="_blank">
We can use either of three option to open in new tab by react routing.
this works fine for me
<Link to={`link`} target="_blank">View</Link>
target="_blank" is enough to open in a new tab, when you are using react-router
eg:
<Link to={
/admin/posts/error-post-list/${this.props.errorDate}}
target="_blank"> View Details </Link>
In my case, I am using another function.
Function
function openTab() {
window.open('https://play.google.com/store/apps/details?id=com.drishya');
}
<Link onClick={openTab}></Link>