Search code examples
vue.jsnuxt.jsvue-router

Is there a way to force vue router to redirect more than once?


I have a view for a route, let's say "form/:step", that reads and controls the route parameter "step". I want to be able to go to said view without specifying the step, and then, based on a set of rules, I set the step parameter with:

this.$router.replace({ params: { step } }) When I navigate to this view through a click, everything is ok. But if I use programmatic navigation (push method) to go to this route, then the replace method fails with:

Uncaught (in promise) Error: Navigation cancelled from "/form" to "/form/step-1" with a new navigation.

Is there a way to force this? I've tried catching the error, but that does not force the redirect.


Solution

  • You need to decide really what your route need to be. But for me, what i understand is your params is optionnal so you just have to add a ?.

    {
        path: '/form/:step?',
    },
    

    The params is now optionnal and you can define a setup or not!