小编iSn*_*uff的帖子

类型错误:无法读取未定义的属性(读取“$router”)vuejs

因此,如果 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)

我也有登录/注册组件,当我使用时 …

javascript vue.js vue-router vuejs2

8
推荐指数
2
解决办法
5万
查看次数

标签 统计

javascript ×1

vue-router ×1

vue.js ×1

vuejs2 ×1