0

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?

jeerbl
  • 7,537
  • 5
  • 25
  • 39
Jamie
  • 10,302
  • 32
  • 103
  • 186

2 Answers2

5

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.

jeerbl
  • 7,537
  • 5
  • 25
  • 39
  • I use vue2. This answer doesn't work on me. This still gets me to homepage. For example, window.location.href = "www.gotosite.com" forwards me to http://example.com/www.gotosite.org – codely Jun 16 '17 at 18:24
  • @noypee this is because your should put `https://` in front of your URL otherwise it just goes to a relative URL – jeerbl Oct 04 '17 at 16:38
1

This should work in vue router 2.0:

this.$router.push({path: '/file/' + file.path , query: {token: localStorage.getItem('jwt-token')} })
Saurabh
  • 71,488
  • 40
  • 181
  • 244