Commit 4f05dce0 authored by chenshouchao's avatar chenshouchao

feat: 解决路由相关问题

parent 41b27713
import style from "./index.module.css"; import style from "./index.module.css";
const CardTable = () => { interface ICardTableProps {
data: Array<any>;
renderItem: any;
}
const CardTable = (props: ICardTableProps) => {
const { data, renderItem } = props;
return <div>CardTable</div>; return <div>CardTable</div>;
}; };
......
...@@ -14,7 +14,6 @@ const Code = (props: ICodeType) => { ...@@ -14,7 +14,6 @@ const Code = (props: ICodeType) => {
return ( return (
<CodeMirror <CodeMirror
height={height || "100%"} height={height || "100%"}
// maxWidth="200px"
width={width || "100%"} width={width || "100%"}
maxWidth={maxWidth || "100%"} maxWidth={maxWidth || "100%"}
value={value} value={value}
......
...@@ -44,12 +44,16 @@ const useMyRouter = () => { ...@@ -44,12 +44,16 @@ const useMyRouter = () => {
}); });
} }
for (let item of menuInfo.res.data) { for (let item of menuInfo.res.data) {
let routeHead = `/${item.type}` || '/'
let childrenRoutes: any = [] let childrenRoutes: any = []
for (let route of item.routes) { for (let route of item.routes) {
route.element = elements[route.element] || NotFound; route.element = elements[route.element] || NotFound;
route.path = `/product/${item.id}${route.path}`; route.path = `${routeHead}/${item.id}${route.path}`
if (Array.isArray(route.children)) { if (Array.isArray(route.children)) {
route.children.forEach((childrenItem: any, index: number) => { route.children.forEach((childrenItem: any, index: number) => {
console.log(route)
console.log(childrenItem)
console.log(routeHead)
if (childrenItem.path) { if (childrenItem.path) {
childrenRoutes.push({ childrenRoutes.push({
...childrenItem, ...childrenItem,
...@@ -59,10 +63,10 @@ const useMyRouter = () => { ...@@ -59,10 +63,10 @@ const useMyRouter = () => {
}) })
} }
}) })
// http://localhost:8088/v3/product/resourceCenter/userResources/seeEnv
route.children = route.children.filter((childrenItem: any) => !childrenItem.path) route.children = route.children.filter((childrenItem: any) => !childrenItem.path)
} }
} }
// permissionStore.setAddRoutes(item.routes);
permissionStore.setAddRoutes([...childrenRoutes, ...item.routes]); permissionStore.setAddRoutes([...childrenRoutes, ...item.routes]);
} }
menuStore.initMenu(menuInfo.res.data); menuStore.initMenu(menuInfo.res.data);
......
...@@ -70,6 +70,11 @@ export const routes: Array<route | navigate> = [ ...@@ -70,6 +70,11 @@ export const routes: Array<route | navigate> = [
from: "/", from: "/",
to: "/home", to: "/home",
}, },
{
type: "navigate",
from: "/utility",
to: "/home",
},
{ {
type: "navigate", type: "navigate",
from: "/product", from: "/product",
...@@ -87,6 +92,13 @@ export const routes: Array<route | navigate> = [ ...@@ -87,6 +92,13 @@ export const routes: Array<route | navigate> = [
path: "/home", path: "/home",
element: Home, element: Home,
}, },
{
type: "page",
name: "Utility",
path: "/utility",
element: MenuLayout,
children: [],
},
{ {
type: "page", type: "page",
name: "Product", name: "Product",
......
...@@ -38,7 +38,11 @@ class Permission { ...@@ -38,7 +38,11 @@ class Permission {
if (route.type === "page" && route.children) { if (route.type === "page" && route.children) {
if (route.name === "Product") { if (route.name === "Product") {
for (let item of this.addRoutes) { for (let item of this.addRoutes) {
route.children.push(...item); route.children.push(...item.filter((a) => a.path.indexOf('product/') !== -1));
}
} else if (route.name === "Utility") {
for (let item of this.addRoutes) {
route.children.push(...item.filter((a) => a.path.indexOf('utility/') !== -1));
} }
} else { } else {
this.AddInsertRoutes(route.children); this.AddInsertRoutes(route.children);
......
...@@ -144,7 +144,7 @@ const SeeEnv = () => { ...@@ -144,7 +144,7 @@ const SeeEnv = () => {
className={style.goBackIcon} className={style.goBackIcon}
src={goback} src={goback}
alt="" alt=""
onClick={() => navigate("/product/resourceCenter/userResources")} onClick={() => navigate("/utility/resourceCenter/userResources")}
/> />
<div className={style.title}>{info.title}</div> <div className={style.title}>{info.title}</div>
<div className={style.type}> <div className={style.type}>
......
...@@ -131,9 +131,7 @@ const UserResourcesEnvironment = () => { ...@@ -131,9 +131,7 @@ const UserResourcesEnvironment = () => {
}; };
const hanleToSeeEnv = (item: any) => { const hanleToSeeEnv = (item: any) => {
console.log("hanleToSeeEnv"); navigate("/utility/resourceCenter/userResources/seeEnv", {
console.log(item.id);
navigate("/product/resourceCenter/userResources/seeEnv", {
state: { id: item.id }, state: { id: item.id },
}); });
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment