mirror of
https://github.com/pure-admin/pure-admin-thin.git
synced 2025-04-25 16:07:19 +08:00
perf: 优化 initRouter
,兼容 sso
场景
This commit is contained in:
parent
80453ec4b1
commit
cb3d7cd552
@ -184,29 +184,34 @@ function handleAsyncRoutes(routeList) {
|
|||||||
addPathMatch();
|
addPathMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 初始化路由 */
|
/** 初始化路由(`new Promise` 写法防止在异步请求中造成无限循环)*/
|
||||||
function initRouter() {
|
function initRouter() {
|
||||||
return new Promise(resolve => {
|
|
||||||
if (getConfig()?.CachingAsyncRoutes) {
|
if (getConfig()?.CachingAsyncRoutes) {
|
||||||
// 开启动态路由缓存本地sessionStorage
|
// 开启动态路由缓存本地sessionStorage
|
||||||
const key = "async-routes";
|
const key = "async-routes";
|
||||||
const asyncRouteList = storageSession.getItem(key) as any;
|
const asyncRouteList = storageSession.getItem(key) as any;
|
||||||
if (asyncRouteList?.length > 0) {
|
if (asyncRouteList && asyncRouteList?.length > 0) {
|
||||||
|
return new Promise(resolve => {
|
||||||
handleAsyncRoutes(asyncRouteList);
|
handleAsyncRoutes(asyncRouteList);
|
||||||
|
resolve(router);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
|
return new Promise(resolve => {
|
||||||
getAsyncRoutes().then(({ data }) => {
|
getAsyncRoutes().then(({ data }) => {
|
||||||
handleAsyncRoutes(data);
|
handleAsyncRoutes(data);
|
||||||
storageSession.setItem(key, data);
|
storageSession.setItem(key, data);
|
||||||
|
resolve(router);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
resolve(router);
|
|
||||||
} else {
|
} else {
|
||||||
|
return new Promise(resolve => {
|
||||||
getAsyncRoutes().then(({ data }) => {
|
getAsyncRoutes().then(({ data }) => {
|
||||||
handleAsyncRoutes(data);
|
handleAsyncRoutes(data);
|
||||||
resolve(router);
|
resolve(router);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user