refactor(projects): 优化路由声明,添加路由模块导入,规范路相关文件夹

This commit is contained in:
Soybean
2021-11-21 18:44:18 +08:00
parent 2fdb5f563f
commit f199794da0
25 changed files with 444 additions and 200 deletions

View File

@ -1,3 +1,4 @@
import type { Component } from 'vue';
import type { RouteRecordRaw } from 'vue-router';
function getCacheName(route: RouteRecordRaw, isCache: boolean) {
@ -5,6 +6,7 @@ function getCacheName(route: RouteRecordRaw, isCache: boolean) {
const hasChild = hasChildren(route);
if (isCache && !hasChild) {
const name = route.name as string;
setComponentName(route.component, name);
cacheNames.push(name);
}
if (hasChild) {
@ -24,6 +26,13 @@ function hasChildren(route: RouteRecordRaw) {
return Boolean(route.children && route.children.length);
}
/** 给需要缓存的页面组件设置名称 */
export function setComponentName(component?: Component, name?: string) {
if (component && name) {
Object.assign(component, { name });
}
}
/** 获取被缓存的路由 */
export function getCacheRoutes(routes: RouteRecordRaw[]) {
const cacheNames: string[] = [];