首页 > 解决方案 > 路线导航期间未捕获的错误:无法读取未定义的属性“应用”

问题描述

尝试通过链接或按钮在页面之间导航时出现此错误,该错误似乎专门在 vue-router.js 源文件中的 boundRouteGuard 函数中引发,似乎guard传递给函数的参数未定义

function bindGuard (guard, instance) {
  if (instance) {
    return function boundRouteGuard () {
     return guard.apply(instance, arguments)
    }
  }
}

这是我的路线文件:

import Vue from 'vue'
import VueRouter from 'vue-router'
import NProgress from 'nprogress'
import i18n from './../plugins/i18n.plugin'
import routes from './routes'
const router = new VueRouter({
 mode: 'history',
 base: process.env.BASE_URL,
 routes,
 linkActiveClass: 'current',
 linkExactActiveClass: 'exact-current'
})
Vue.use(VueRouter);

router.beforeEach((to, from, next) => {
  function redirectToLogin () {
    next({ name: 'login', query: { redirectFrom: to.fullPath } })
  }



 // If this isn't an initial page load...
 if (from.name !== null) {
  NProgress.start()
 }


 document.title = to.meta.title || i18n.t('app.title')

 const authRequired = to.matched.some(record => record.meta.authRequired)
 const token = localStorage.getItem('tokenData')

 if (authRequired && !token && to.name !== 'login') {
   redirectToLogin()
 } else {
  console.log(to.path)
  next()
 }
})


// When each route is finished evaluating...
router.afterEach(() => {
 // Complete the animation of the route progress bar.
 NProgress.done()
})

export default router

标签: vue.jsvue-router

解决方案


推荐阅读