Jamie
Jamie

Reputation: 10886

Going to a URL using VueJS

I'm trying to go to a URL like this:

methods: {
    show (file) {
        this.$router.go('/file/' + file.path + '?token=' + localStorage.getItem('jwt-token'));
    }
}

I'm not trying to go to a component. I just want to go to the following URL:

'/file/' + file.path + '?token=' + localStorage.getItem('jwt-token')

But it does not work. It's redirecting me to the home page.

How can I get this done?

Upvotes: 0

Views: 6326

Answers (2)

Saurabh
Saurabh

Reputation: 73589

This should work in vue router 2.0:

this.$router.push({path: '/file/' + file.path , query: {token: localStorage.getItem('jwt-token')} })

Upvotes: 1

jeerbl
jeerbl

Reputation: 7867

If you want to go to a URL which is not a Vue router URL, you can do it using standard javascript via:

window.location.href = '/file/' + file.path + '?token=' + localStorage.getItem('jwt-token');

See this answer.

Upvotes: 5

Related Questions