mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-07 08:57:19 +08:00
fix: router
This commit is contained in:
parent
e97bd9c8c4
commit
438aab9bfc
@ -70,6 +70,42 @@ const permissionRouter = {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const tabsRouter = {
|
||||||
|
path: "/tabs",
|
||||||
|
name: "reTabs",
|
||||||
|
redirect: "/tabs/index",
|
||||||
|
meta: {
|
||||||
|
icon: "IF-team-icontabs",
|
||||||
|
title: "message.hstabs",
|
||||||
|
i18n: true,
|
||||||
|
showLink: true,
|
||||||
|
rank: 8
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: "/tabs/index",
|
||||||
|
name: "reTabs",
|
||||||
|
meta: {
|
||||||
|
title: "message.hstabs",
|
||||||
|
showLink: true,
|
||||||
|
i18n: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/tabs/detail",
|
||||||
|
name: "tabDetail",
|
||||||
|
meta: {
|
||||||
|
title: "",
|
||||||
|
showLink: false,
|
||||||
|
i18n: false,
|
||||||
|
dynamicLevel: 3,
|
||||||
|
realPath: "/tabs/detail",
|
||||||
|
refreshRedirect: "/tabs/index"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
// 添加不同按钮权限到/permission/button页面中
|
// 添加不同按钮权限到/permission/button页面中
|
||||||
function setDifAuthority(authority, routes) {
|
function setDifAuthority(authority, routes) {
|
||||||
routes.children[1].meta.authority = [authority];
|
routes.children[1].meta.authority = [authority];
|
||||||
@ -84,12 +120,16 @@ export default [
|
|||||||
if (query.name === "admin") {
|
if (query.name === "admin") {
|
||||||
return {
|
return {
|
||||||
code: 0,
|
code: 0,
|
||||||
info: [systemRouter, setDifAuthority("v-admin", permissionRouter)]
|
info: [
|
||||||
|
tabsRouter,
|
||||||
|
systemRouter,
|
||||||
|
setDifAuthority("v-admin", permissionRouter)
|
||||||
|
]
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
code: 0,
|
code: 0,
|
||||||
info: [setDifAuthority("v-test", permissionRouter)]
|
info: [tabsRouter, setDifAuthority("v-test", permissionRouter)]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ router.beforeEach((to: toRouteType, _from, next) => {
|
|||||||
meta
|
meta
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子)
|
// 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对静态路由)
|
||||||
if (to.meta?.realPath) {
|
if (to.meta?.realPath) {
|
||||||
const routes = router.options.routes;
|
const routes = router.options.routes;
|
||||||
const { refreshRedirect } = to.meta;
|
const { refreshRedirect } = to.meta;
|
||||||
@ -111,13 +111,28 @@ router.beforeEach((to: toRouteType, _from, next) => {
|
|||||||
: router.options.routes;
|
: router.options.routes;
|
||||||
const route = findRouteByPath(path, routes);
|
const route = findRouteByPath(path, routes);
|
||||||
const routePartent = getParentPaths(path, routes);
|
const routePartent = getParentPaths(path, routes);
|
||||||
handTag(
|
// 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对动态路由)
|
||||||
route.path,
|
if (routePartent.length === 0) {
|
||||||
routePartent[routePartent.length - 1],
|
const { name, meta } = findRouteByPath(
|
||||||
route.name,
|
route?.meta?.refreshRedirect,
|
||||||
route.meta
|
routes
|
||||||
);
|
);
|
||||||
return router.push(path);
|
handTag(
|
||||||
|
route.meta?.refreshRedirect,
|
||||||
|
getParentPaths(route.meta?.refreshRedirect, routes)[0],
|
||||||
|
name,
|
||||||
|
meta
|
||||||
|
);
|
||||||
|
return router.push(route.meta?.refreshRedirect);
|
||||||
|
} else {
|
||||||
|
handTag(
|
||||||
|
route.path,
|
||||||
|
routePartent[routePartent.length - 1],
|
||||||
|
route.name,
|
||||||
|
route.meta
|
||||||
|
);
|
||||||
|
return router.push(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
router.push(to.path);
|
router.push(to.path);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
// 静态路由
|
// 静态路由
|
||||||
import tabsRouter from "./tabs";
|
|
||||||
import homeRouter from "./home";
|
import homeRouter from "./home";
|
||||||
import errorRouter from "./error";
|
import errorRouter from "./error";
|
||||||
import editorRouter from "./editor";
|
import editorRouter from "./editor";
|
||||||
@ -18,7 +17,6 @@ import {
|
|||||||
|
|
||||||
// 原始静态路由(未做任何处理)
|
// 原始静态路由(未做任何处理)
|
||||||
const routes = [
|
const routes = [
|
||||||
tabsRouter,
|
|
||||||
homeRouter,
|
homeRouter,
|
||||||
errorRouter,
|
errorRouter,
|
||||||
nestedRouter,
|
nestedRouter,
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
import Layout from "/@/layout/index.vue";
|
|
||||||
|
|
||||||
const tabsRouter = {
|
|
||||||
path: "/tabs",
|
|
||||||
name: "reTabs",
|
|
||||||
component: Layout,
|
|
||||||
redirect: "/tabs/index",
|
|
||||||
meta: {
|
|
||||||
icon: "IF-team-icontabs",
|
|
||||||
title: "message.hstabs",
|
|
||||||
i18n: true,
|
|
||||||
showLink: true,
|
|
||||||
rank: 8
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: "/tabs/index",
|
|
||||||
name: "reTabs",
|
|
||||||
component: () => import("/@/views/tabs/index.vue"),
|
|
||||||
meta: {
|
|
||||||
title: "message.hstabs",
|
|
||||||
showLink: true,
|
|
||||||
i18n: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/tabs/detail/:id",
|
|
||||||
name: "tabDetail",
|
|
||||||
component: () => import("/@/views/tabs/tabDetail.vue"),
|
|
||||||
meta: {
|
|
||||||
title: "",
|
|
||||||
showLink: false,
|
|
||||||
i18n: false,
|
|
||||||
dynamicLevel: 3,
|
|
||||||
realPath: "/tabs/detail",
|
|
||||||
refreshRedirect: "/tabs/index"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
export default tabsRouter;
|
|
@ -216,7 +216,11 @@ const addAsyncRoutes = (arrRoutes: Array<RouteRecordRaw>) => {
|
|||||||
if (v.redirect) {
|
if (v.redirect) {
|
||||||
v.component = Layout;
|
v.component = Layout;
|
||||||
} else {
|
} else {
|
||||||
v.component = modulesRoutes[`/src/views${v.path}/index.vue`];
|
if (v.meta.realPath) {
|
||||||
|
v.component = modulesRoutes[`/src/views${v.meta.realPath}/index.vue`];
|
||||||
|
} else {
|
||||||
|
v.component = modulesRoutes[`/src/views${v.path}/index.vue`];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (v.children) {
|
if (v.children) {
|
||||||
addAsyncRoutes(v.children);
|
addAsyncRoutes(v.children);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useRoute } from "vue-router";
|
import { useRoute } from "vue-router";
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const index = route.params?.id ?? -1;
|
const index = route.query?.id ?? -1;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
@ -9,7 +9,7 @@ const activeName = ref("tag");
|
|||||||
|
|
||||||
function toDetail(index: number) {
|
function toDetail(index: number) {
|
||||||
useMultiTagsStoreHook().handleTags("push", {
|
useMultiTagsStoreHook().handleTags("push", {
|
||||||
path: `/tabs/detail/${index}`,
|
path: `/tabs/detail`,
|
||||||
parentPath: route.matched[0].path,
|
parentPath: route.matched[0].path,
|
||||||
name: "tabDetail",
|
name: "tabDetail",
|
||||||
meta: {
|
meta: {
|
||||||
@ -20,7 +20,7 @@ function toDetail(index: number) {
|
|||||||
realPath: "/tabs/detail"
|
realPath: "/tabs/detail"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
router.push(`/tabs/detail/${index}`);
|
router.push({ name: "tabDetail", query: { id: index } });
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user