refactor(projects): 路由声明重构,添加composables,BaseLayout进行中,文件夹规范

This commit is contained in:
Soybean
2021-11-19 01:33:36 +08:00
parent 1c5fdca596
commit 1e84d13d54
75 changed files with 668 additions and 565 deletions

View File

@ -1,16 +1,7 @@
import type { Component } from 'vue';
import { EnumRoutePath } from '@/enum';
import type { RoutePathKey, CustomRoute } from '@/interface';
import type { CustomRoute } from '@/interface';
import { router } from '@/router';
/** 获取路由name map */
function getRouteNameMap() {
return new Map<RoutePathKey, RoutePathKey>((Object.keys(EnumRoutePath) as RoutePathKey[]).map(v => [v, v]));
}
/** 路由名称 */
export const ROUTE_NAME_MAP = getRouteNameMap();
/** 给需要缓存的页面组件设置名称 */
export function setRouterCacheName(component: Component, name?: string) {
if (name) {
@ -20,8 +11,8 @@ export function setRouterCacheName(component: Component, name?: string) {
/** 获取登录后的重定向地址 */
export function getLoginRedirectUrl() {
const path = router.currentRoute.value.fullPath as EnumRoutePath;
const redirectUrl = path === EnumRoutePath.root ? undefined : path;
const path = router.currentRoute.value.fullPath as string;
const redirectUrl = path === '/' ? undefined : path;
return redirectUrl;
}
@ -31,12 +22,12 @@ export function getLoginRedirectUrl() {
* @param notFoundName - 404未找到的路由名称
* @param container - 路由容器
*/
export function setSingleRoute(container: Component, route: CustomRoute) {
export function setSingleRoute(container: Component, route: CustomRoute, notFoundName = 'not-found') {
const routeItem: CustomRoute = {
name: `${route.name as string}_`,
path: `${route.path}_`,
component: container,
redirect: { name: ROUTE_NAME_MAP.get('not-found') },
redirect: { name: notFoundName },
meta: {
isNotMenu: true
},