|
|
@ -14,7 +14,26 @@ const getRouter = async() => { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
async function handleKeepAlive(to) { |
|
|
|
if (to.matched && to.matched.length > 2) { |
|
|
|
for (let i = 1; i < to.matched.length; i++) { |
|
|
|
const element = to.matched[i - 1] |
|
|
|
if (element.name === "layout") { |
|
|
|
to.matched.splice(i, 1) |
|
|
|
await handleKeepAlive(to) |
|
|
|
} |
|
|
|
// 如果没有按需加载完成则等待加载
|
|
|
|
if (typeof element.components.default === 'function') { |
|
|
|
await element.components.default() |
|
|
|
await handleKeepAlive(to) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
router.beforeEach(async(to, from, next) => { |
|
|
|
to.meta.matcheds =JSON.parse(JSON.stringify(to.matched)) |
|
|
|
handleKeepAlive(to) |
|
|
|
const token = store.getters['user/token'] |
|
|
|
// 在白名单中的判断情况
|
|
|
|
document.title = getPageTitle(to.meta.title) |
|
|
@ -35,6 +54,7 @@ router.beforeEach(async(to, from, next) => { |
|
|
|
if (!asyncRouterFlag) { |
|
|
|
asyncRouterFlag++ |
|
|
|
await getRouter() |
|
|
|
|
|
|
|
next({...to, replace: true }) |
|
|
|
} else { |
|
|
|
if (to.matched.length) { |
|
|
|