I know we can use a Link tag and pass in target="_blank" like
<Link to="/" target="_blank">Hello World</Link>
but I am having trouble finding out I can do that with this.props.history.push... I am using that to pass in a pathname and search string...
let searchString = queryString.stringify({
rangeEnd: data.programEnd,
});
this.props.history({
pathname: `/machines/${machineId}`,
search: searchString,
target: "_blank // need something like this, not seeing it in docs
});
Using history.push() is another approach where we make use of the history props React Router provides while rendering a component. In other words, this works when the component is being rendered by React Router, bypassing the component as a Component prop to a Route.
The history. push() function belongs to react-router-dom and used to move from the current page to another one. It takes the first argument as a destination path and a second argument as the state. Note: You can only use this.
To recap, if you need to pass data from Link through to the new component that's being rendered, pass Link s a state prop with the data you want to pass through. Then, to access the Link s state property from the component that's being rendered, use the useLocation Hook to get access to location.
React Router uses the history package, which builds on the browser history API to provide an interface to which we can use easily in React apps. location - (object) The current location. May have the following properties: pathname - (string) The path of the URL.
History push changes address in the same window.
One option could be using window.open()
const url = `#/machines/${machineId}?${searchString}`;
window.open(url);
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