Čamo
Čamo

Reputation: 4163

How to redirect in Nuxt Vue application

I have a delete action in Nuxt application. And after a successful delete I need to redirect the user to another page. But in Nuxt router documentation, there is no mention about redirecting. So the question is how to do it in component?

Upvotes: 0

Views: 6232

Answers (3)

Mohammad Nadr
Mohammad Nadr

Reputation: 533

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

Upvotes: 0

kissu
kissu

Reputation: 46594

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

Upvotes: 7

pkorhone
pkorhone

Reputation: 132

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.

Upvotes: 1

Related Questions