I need to open a link to a new tab after doing some logic.
I have a button like this:
<Button
onClick={handleSubmit}
>
Preview
</Button>
with the handleSubmit() being:
const history = useHistory();
const handleSubmit = () => {
console.log("doing something");
history.push("/some-link")
}
As you can see, with my usecase it wouldn't make sense to use the Link
component.
So, is there a way to push that link to a new tab, using only history.push()
React-router's history is meant to be used just for the navigation of your application and some persistance. I can't see why you need to use it to open a new tab. I think you should use the window object for this.
const handleSubmit = () => {
console.log("doing something");
const win = window.open("/some-link", "_blank");
win.focus();
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments