【问题标题】:How can I redirect to specific route before entering route? VueRouter如何在进入路线之前重定向到特定路线? Vue路由器
【发布时间】:2020-03-24 06:36:15
【问题描述】:

如何在进入路线之前重定向到特定路线? 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'
            },

        ],
    }

];

【问题讨论】:

    标签: vue.js routing vue-router


    【解决方案1】:

    你需要使用 beforeEnter 而不是 beforeEach:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-20
      • 1970-01-01
      • 1970-01-01
      • 2018-04-13
      • 2021-12-17
      • 1970-01-01
      • 2018-04-09
      相关资源
      最近更新 更多