Commit 05b3171c authored by 罗超's avatar 罗超

調整

parent 811247e8
import { AuthMenuType } from '../@types' import { AuthMenuType } from '../@types'
import { ResultType } from '../@types/enumHelper' import { ResultType } from '../@types/enumHelper'
import router from '../router/index' import { boot } from 'quasar/wrappers'
import { getAuth, getUserAllMenu } from '../utils/auth' import { getAuth, getUserAllMenu } from '../utils/auth'
import { LoadingBar } from 'quasar' import { LoadingBar } from 'quasar'
...@@ -13,9 +13,9 @@ LoadingBar.setDefaults({ ...@@ -13,9 +13,9 @@ LoadingBar.setDefaults({
let loadAsyncRouter = false let loadAsyncRouter = false
const whiteList = ['/auth/login','/auth/regist','/auth/forget','/auth/newpassword'] const whiteList = ['/auth/login','/auth/regist','/auth/forget','/auth/newpassword','/404']
export default boot(({ router, store }) => {
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
localStorage.setItem('routerBefore', from.path) localStorage.setItem('routerBefore', from.path)
LoadingBar.start() LoadingBar.start()
/** 请求头包含授权信息 并且 页面必须授权 直接进入 */ /** 请求头包含授权信息 并且 页面必须授权 直接进入 */
...@@ -75,24 +75,28 @@ router.beforeEach((to, from, next) => { ...@@ -75,24 +75,28 @@ router.beforeEach((to, from, next) => {
let urlPath=to.matched[0].path let urlPath=to.matched[0].path
if(urlPath.indexOf('/:')!=-1) urlPath=urlPath.substring(0,urlPath.indexOf('/:')) if(urlPath.indexOf('/:')!=-1) urlPath=urlPath.substring(0,urlPath.indexOf('/:'))
if (whiteList.indexOf(urlPath) !== -1) { if (whiteList.indexOf(urlPath) !== -1) {
console.log(whiteList,to.path) console.log(whiteList,to,'do something')
next() next()
} else { } else {
next(`/auth/login?redirect=${decodeURIComponent(to.path)}`) // 否则全部重定向到登录页 next(`/auth/login?redirect=${decodeURIComponent(to.path)}`) // 否则全部重定向到登录页
LoadingBar.stop() LoadingBar.stop()
} }
} }
}) })
router.afterEach(() => { router.afterEach(() => {
LoadingBar.stop() // 结束Progress LoadingBar.stop() // 结束Progress
}) })
router.onError(error => {
router.onError(error => {
const pattern = /Loading chunk (\d)+ failed/g const pattern = /Loading chunk (\d)+ failed/g
const isChunkLoadFailed = error.message.match(pattern) const isChunkLoadFailed = error.message.match(pattern)
const targetPath = error.to const targetPath = error.to
console.log('異常:',error,targetPath)
if (isChunkLoadFailed) { if (isChunkLoadFailed) {
router.replace(targetPath) router.replace(targetPath)
} }
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment