How to pass parameters on redirecting using Vue Router

You can use a function for dynamic redirecting, as per the Vue docs.

Here's an example taking a param (e.g. yourdomain.com/:yourParam) and redirecting to another URL, using the param (yourParam) as a query string (yourdomain.com/your/route?yourQueryString=:yourParam):

redirect: to => ({
  name: "your-named-route",
  query: { yourQueryString: to.params.yourParam },
}),

note: this syntax is using ES6.


You can make /:id as optional in login routes as follows:-

router = new VueRouter({
         routes: [
             {path: '/form/:id', redirect: '/login/:id'},
             {path: '/login/:id?', name: 'Login', component: Login}
         ]
     });

With above snippet of code you will get this.$route.params.id in login component.