fix: 🐛 补充 basePath 父级路径

Former-commit-id: cce921b52b3f93fb9be8d9619c788a5b1b585fe9
This commit is contained in:
hxr
2023-08-15 05:35:35 +08:00
parent e01e221106
commit e03d73bb48
4 changed files with 36 additions and 9 deletions

View File

@@ -5,6 +5,9 @@ import { useSettingsStore } from "@/store/modules/settings";
import { useAppStore } from "@/store/modules/app";
import variables from "@/styles/variables.module.scss";
import path from "path-browserify";
import { isExternal } from "@/utils/index";
const settingsStore = useSettingsStore();
const appStore = useAppStore();
const currRoute = useRoute();
@@ -17,7 +20,29 @@ const props = defineProps({
},
type: Array<any>,
},
basePath: {
type: String,
required: true,
},
});
/**
* 解析路径
*
* @param routePath 路由路径
*/
function resolvePath(routePath: string) {
if (isExternal(routePath)) {
return routePath;
}
if (isExternal(props.basePath)) {
return props.basePath;
}
// 完整路径 = 父级路径(/level/level_3) + 路由路径
const fullPath = path.resolve(props.basePath, routePath); // 相对路径 → 绝对路径
return fullPath;
}
</script>
<template>
<el-menu
@@ -34,7 +59,7 @@ const props = defineProps({
v-for="route in menuList"
:key="route.path"
:item="route"
:base-path="route.path"
:base-path="resolvePath(route.path)"
:is-collapse="!appStore.sidebar.opened"
/>
</el-menu>