From 7244efb05811bd4a4994adce3421e699aa22cb26 Mon Sep 17 00:00:00 2001 From: BoBoooooo <17746714@qq.com> Date: Mon, 11 Mar 2019 07:23:01 +0800 Subject: [PATCH] =?UTF-8?q?[fix]{permission}:=20=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/permission.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/permission.js b/src/permission.js index 5d26b0f..777ed3e 100644 --- a/src/permission.js +++ b/src/permission.js @@ -15,7 +15,7 @@ import { } from '@/utils/auth'; // 验权 const whiteList = ['/login']; -router.beforeEach(async (to, next) => { +router.beforeEach((to, from, next) => { NProgress.start(); if (getToken()) { if (to.path === '/login') { @@ -23,21 +23,23 @@ router.beforeEach(async (to, next) => { path: '/', }); } else if (store.getters.addRouters.length === 0) { - const res = await store.dispatch('GetInfo') // 拉取user_info - const roleauthname = res.RoleAuthName.split(',') - await store.dispatch('GenerateRoutes', { - roleauthname, - }) - // 根据roles权限生成可访问的路由表 - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 - next({ - ...to, - replace: true, + store.dispatch('GetInfo').then((res) => { // 拉取user_info + const roleauthname = res.RoleAuthName.split(',') + store.dispatch('GenerateRoutes', { + roleauthname, + }).then(() => { // 根据roles权限生成可访问的路由表 + router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 + next({ + ...to, + replace: true, + }) + // hack方法 确保addRoutes已完成 + }) }) } else { next() } - } else if (whiteList.includes(to.path)) { + } else if (whiteList.indexOf(to.path) !== -1) { next() } else { next('/login')