Categories
Vue Answers

How to navigate using vue router from Vuex actions?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *