Categories
Vue Answers

How to Open a Link in a New Tab with Vue Router?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *