vue.js - 路线导航期间未捕获的错误:无法读取未定义的属性“应用”
问题描述
尝试通过链接或按钮在页面之间导航时出现此错误,该错误似乎专门在 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
解决方案
推荐阅读
- command - 说话时呈现 Alexa 演示语言文档
- terminal - vscode 到 sqlite 的终端路径不保存
- spring-boot - 如何使用自定义验证器验证列表中的每个条目
- c++ - 对象或静态中的 C++ 方法
- kubernetes - 使用 minikube 配置 apiserver 以使用加密配置
- java - 尝试更新字符串字段时出现 java.sql.SQLSyntaxErrorException
- javascript - 正则表达式不包含
- ansible - 如何使用 ansible_mounts 从特定挂载调整大小?
- c++ - c和c++中函数指针转换的区别
- javascript - 为什么某个 DOM 元素不能有 CSS 样式