Sometimes, we want to open a link in a new window with Vue Router.
In this article, we’ll look at how to open a link in a new window with Vue Router.
Open a Link in a New Tab with Vue Router
We can open a link in a new tab with Vue Router.
For instance, we can write:
const routeData = this.$router.resolve({ name: 'foo', query: { data: "bar" }});
window.open(routeData.href, '_blank');
We call the this.$router.resolve
method to get the URL to open.
Then we call window.open
to open the given URL.
The first argument is the URL.
'_blank'
indicates that we open the URL in a new tab.
Conclusion
We can open a link in a new tab with Vue Router.