因此,如果 api 调用返回状态 422,我尝试将用户重定向到不同的路线。但我收到错误
TypeError: Cannot read properties of undefined (reading '$router')
Run Code Online (Sandbox Code Playgroud)
我的routes.js:
{
path: '/dashboard',
component: Dashboard,
name: 'Dashboard',
beforeEnter: (to, form, next) =>{
axios.get('/api/authenticated')
.then(()=>{
next();
}).catch(()=>{
return next({ name: 'Login'})
})
},
children: [
{
path: 'documentCollections',
component: DocumentCollection,
name: 'DocumentCollections'
},
{
path: 'document',
component: Document,
name: 'Document'
},
{
path: 'createDocument',
component: CreateDocument,
name: 'CreateDocument'
},
{
path: 'suppliers',
component: Suppliers,
name: 'Suppliers'
},
{
path: 'settings',
component: Settings,
name: 'Settings'
},
]
}
Run Code Online (Sandbox Code Playgroud)
我也有登录/注册组件,当我使用时 …