[Vuejs]-How to redirect in Nuxt Vue application

5👍

You can totally use either

<nuxt-link :to="{ name: 'my-fancy-route' }">Go to</nuxt-link>

or

this.$router.push({ name: 'my-fancy-route' })

Depending on what you’re trying to achieve here.

Also, all of your routes can be found with the Vue devtools, go to Routing > Routes and you will be able to see them all there.

enter image description here

For more info, Nuxt is using vue-router behind the curtains, so a reference to this part of the documentation will be good: https://router.vuejs.org/guide/essentials/navigation.html#router-push-location-oncomplete-onabort

👤kissu

1👍

As mentioned, you can use this.$router.push(yourPath) to redirect the user. You should be able to use either the route name or explicit path in place of yourPath. If you’re unsure of the route names generated by Nuxt, you can view them in .nuxt/routes.json.

Note that Nuxt uses Vue router so, for more detailed documentation, you might want to read this.

0👍

this.$router.push({
                path: '/your-path',
            });

Leave a comment