Menu Close

How to navigate using vue router from Vuex actions?

Sometimes, we want to navigate using vue router from Vuex actions.

In this article, we’ll look at how to navigate using vue router from Vuex actions.

How to navigate using vue router from Vuex actions?

To navigate using vue router from Vuex actions, we can call router.push.

For instance, we write

import router from "@/router";

//...

router.push({ name: "Home" });

to import the Vue Router object with import.

And then we call router.push with an object to navigate to the route with name set to 'Home'.

We can do this outside components.

Conclusion

To navigate using vue router from Vuex actions, we can call router.push.

Posted in vue