修改判断token是否存在的写法
[缺陷描述]:
store.dispatch('GetInfo')重复调用。
[重现步骤]:
1.设定dashboard页面也是需要权限才能访问。
2.进入login页面,正常登录系统。
3.点击右上角按钮,正常登出系统。
[期望结果]:
直接跳转到登录页面。
[实际结果]:
store.dispatch('GetInfo')被调用,没有直接跳转到登录页面。
[原因定位]:
严格模式下,if(getToken())不能判断token不存在的情况。需要使用if (typeof (token) === 'undefined')来进行判断。
[修复建议]:
if(getToken())
修改为
const token = getToken()
if (typeof (token) !== 'undefined') {
This commit is contained in:
@@ -19,7 +19,7 @@ const whiteList = ['/login', '/authredirect']// no redirect whitelist
|
||||
router.beforeEach((to, from, next) => {
|
||||
NProgress.start() // 开启Progress
|
||||
const token = getToken()
|
||||
if (typeof (token) === 'undefined') { // 判断是否有token
|
||||
if (typeof (token) !== 'undefined') { // 判断是否有token
|
||||
if (to.path === '/login') {
|
||||
next({ path: '/' })
|
||||
NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it
|
||||
|
||||
Reference in New Issue
Block a user