修改判断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:
phoenix110 2018-03-20 17:29:40 +08:00 committed by GitHub
parent bb9bff00af
commit 7a8304131d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -19,7 +19,7 @@ const whiteList = ['/login', '/authredirect']// no redirect whitelist
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start() // 开启Progress NProgress.start() // 开启Progress
const token = getToken() const token = getToken()
if (typeof (token) === 'undefined') { // 判断是否有token if (typeof (token) !== 'undefined') { // 判断是否有token
if (to.path === '/login') { if (to.path === '/login') {
next({ path: '/' }) next({ path: '/' })
NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it