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?

2
  • 2
    vue router 1 or 2? Commented Nov 10, 2016 at 17:53
  • Did you find out? Any of the answers below helped you? Commented Nov 15, 2016 at 11:11

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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 example.com/www.gotosite.org
@noypee this is because your should put https:// in front of your URL otherwise it just goes to a relative URL
1

This should work in vue router 2.0:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.