ali dehqani
ali dehqani

Reputation: 184

How can I redirect to specific route before entering route? VueRouter

How can I redirect to a specific route before entering route? VueRouter

This is my router config and I'm using "beforeEach" method but it's not working correctly.

const routes=[

    {
        path:'/',
        name:'index',
        component:index,
        beforeEach:((to,from,next)=>{
          next('/content')
        }),
        children:[
            {
                path:"content",
                component:content,
                name:'content'
            },
            {
                path:"requestDemand",
                component:requestDemand,
                name:'requestDemand'
            },
            {
                path:"newReport",
                component:newReport,
                name:'newReport'
            },
            {
                path:"lastestDemand",
                component:lastestDemand,
                name:'lastestDemand'
            },

        ],
    }

];

Upvotes: 1

Views: 1323

Answers (1)

dako
dako

Reputation: 1173

You need to use beforeEnter instead of beforeEach:

beforeEnter:((to,from,next)=>{
  next('/content')
}),

Upvotes: 1

Related Questions