Home > OS >  Nuxtjs bad routing in Netlify
Nuxtjs bad routing in Netlify

Time:04-14

I have a NuxtJs (vue) application in Netlify, when I redirect to other pages, It will to concat the last page and the next.

For example:

https://page-example/register

I'm in this page, then I redirect to the next page with

this.$router.push("confirmationsend");

In local I get this url :

https://localhost:3001/confirmationsend

but in Netlify I get this url:

https://page-example/register/confirmationsend

And NuxtJs can't resolve this routing.

CodePudding user response:

You could either be pushing a path, like this

this.$router.push('/confirmationsend')
// equivalent to this.$router.push({ path: '/confirmationsend' })

or use the name property (you can find the name in either your router file if you got one or in the Vue devtools)

$router.push({ name: 'confirmationsend' })

As shown in the Vue router documentation.
Mixing both (name path) is usually not a good idea since a push without a / is by default meaning "append it to my current route" in the context of a History push.

Hence why I do recommend any of the snippets above to be more explicit regarding what you're trying to tell to the Vue router/various hosting platforms.

  • Related