Redirect to a set of routes in Vuejs
Devmnj • Sat Jun 19 2021
0 min read
do when want to redirect same route against a bunch of routes ?. Here the alias came into picture
alias can be used in our index route file to redirect a route / a set of route to specific route. The following example will clarify this
Source code
import Vue from "vue";
 ......
Vue.use(VueRouter);
const routes = \[
  {
    path: "/",
    name: "Line",
    component: LineChart,
     },   
  {
    // The redirect can also be targeting a named route:
    path: "/help",
    redirect: { name: 'About' }
  },
  {
    //redirect with aliad
    path: "/doughnut",
    name: "Doughnut",
    component: Doughnut,
    alias: \['/donut', '/dot'\]
  }, 
\];
const router = new VueRouter({
  routes
});
export default router;In the above router configuration I have a route doughnut which shows the doughnut chart. All I want to different routes set to this route. we redirect /doughnut route to the /donut, /dot routes. As a result all the routes are working