Javascript VueJS中子路由的条件路由
我想知道如何有条件地重定向儿童路线。我试过很多方法,但都不管用 我使用存储区中的状态作为重定向子路由的条件。我已从存储所在的文件中导出存储,并将其导入routes.js: 从“@/store”导入存储 以下是处理路由的代码:Javascript VueJS中子路由的条件路由,javascript,vue.js,vuejs2,vuex,vue-router,Javascript,Vue.js,Vuejs2,Vuex,Vue Router,我想知道如何有条件地重定向儿童路线。我试过很多方法,但都不管用 我使用存储区中的状态作为重定向子路由的条件。我已从存储所在的文件中导出存储,并将其导入routes.js: 从“@/store”导入存储 以下是处理路由的代码: { path: '/import', component: Layout, redirect: '/import/table', name: 'Import', meta: { title: 'Import', icon: 'el-icon-right' }, childr
{
path: '/import',
component: Layout,
redirect: '/import/table',
name: 'Import',
meta: { title: 'Import', icon: 'el-icon-right' },
children: [
{
path: 'tree',
name: 'Tree',
component: () =>
import('@/views/tree/import'),
beforeEach: (to,from,next) => {
//store.state.userRole = 'Admin' redirect the route, otherwise not redirect.
if(store.state.userRole = 'Admin') {
next();
}
else {
next(false);
}
meta: { title: 'Create form', icon: 'el-icon-circle-plus-outline' },
},
{
path: 'table',
name: 'Table',
component: () => import('@/views/table/importList'),
meta: { title: 'List', icon: 'el-icon-document' },
},
]
}
每条路线警卫的正确名称为
beforeEnter
-而不是beforeech
哎呀,我的错!!非常感谢你帮助我