如何在进入路线之前重定向到特定路线? Vue路由器

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

如何在输入路由之前重定向到特定路由? Vue路由器

这是我的路由器配置,我正在使用 "beforeEach" 方法,但它无法正常工作。

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'
            },

        ],
    }

];

您需要使用 beforeEnter 而不是 beforeEach:

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