mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-07 17:07:19 +08:00
fix: 采用import.meta.glob方法匹配动态路由
This commit is contained in:
parent
07aff1fcfc
commit
ad0281839f
@ -10,6 +10,9 @@ import permissionRouter from "./modules/permission";
|
|||||||
import remainingRouter from "./modules/remaining"; //静态路由
|
import remainingRouter from "./modules/remaining"; //静态路由
|
||||||
import Layout from "/@/layout/index.vue";
|
import Layout from "/@/layout/index.vue";
|
||||||
|
|
||||||
|
// https://cn.vitejs.dev/guide/features.html#glob-import
|
||||||
|
const modulesRoutes = import.meta.glob("/src/views/*/*/*.vue");
|
||||||
|
|
||||||
import { getAsyncRoutes } from "/@/api/routes";
|
import { getAsyncRoutes } from "/@/api/routes";
|
||||||
import { storageSession } from "../utils/storage";
|
import { storageSession } from "../utils/storage";
|
||||||
import { i18n } from "/@/plugins/i18n/index";
|
import { i18n } from "/@/plugins/i18n/index";
|
||||||
@ -31,9 +34,7 @@ const addAsyncRoutes = (arrRoutes: Array<string>) => {
|
|||||||
if (v.redirect) {
|
if (v.redirect) {
|
||||||
v.component = Layout;
|
v.component = Layout;
|
||||||
} else {
|
} else {
|
||||||
// https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations
|
v.component = modulesRoutes[`/src/views${v.path}/index.vue`];
|
||||||
v.component = () =>
|
|
||||||
import(/* @vite-ignore */ `/@/views${v.path}/index.vue`);
|
|
||||||
}
|
}
|
||||||
if (v.children) {
|
if (v.children) {
|
||||||
addAsyncRoutes(v.children);
|
addAsyncRoutes(v.children);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<h4>
|
<h4>
|
||||||
当前角色:
|
当前角色:
|
||||||
<span style="font-size:26px">{{ purview }}</span>
|
<span style="font-size:26px">{{ purview }}</span>
|
||||||
<p style="color: #FFA500">查看左侧菜单变化(系统管理),模拟后台根据不同角色返回对应路由</p>
|
<p style="color:#FFA500">查看左侧菜单变化(系统管理),模拟后台根据不同角色返回对应路由</p>
|
||||||
</h4>
|
</h4>
|
||||||
<el-button type="primary" @click="changRole">切换角色</el-button>
|
<el-button type="primary" @click="changRole">切换角色</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user