3

I want to do this.$router.push(path) inside module file of vuex. As this is not defined there, how could I perform this.

skns
  • 132
  • 1
  • 8

1 Answers1

3

Just import the router and you'll be able to use it, like this:

import router from 'path/to/router'

router.push(path)

Why does it work like this:

In a Vue file, this is binded to the Vue object which is why you can use certain methods that are available there like $router or $store.

However in a normal JS file this is just binded to the global object that does not contain any of Vue's special functionality, which is why you have to import the router manually.

Yair Cohen
  • 2,032
  • 7
  • 13