Vuejs Vue-Router Linking an External Website

Vue router linking external websites

You can do smth like:

[
{stuff..., "URL":"https://www.google.com/", "external" : true},
{stuff..., "URL":"/internal-link", "external": false}
]

And then in vue component

<div class="mobile-link" v-for="link in json" :key="link.id">
<a v-if="link.external" :href="link.url">{{ link.Name }]</a>
<router-link v-else :to="link.Url">{{link.Name}}</router-link>
</div>

If you can't edit your Array directly, use map function with regex ^(http|https)://.

How to define the route to external link with query

There are 3 params in beforeEnter

Your code should be like this:

beforeEnter(to, from, next) {
location.href = '/path=' + to.query.path
next()
}

Programmatically redirect to URL outside the vue-router app but on the same domain?

All you need is:

window.location.href = "http://example.com";


Related Topics



Leave a reply



Submit