我有一个SideNav菜单,它查找一个名为route.js的文件,该文件的内部有一个称为路由的数组。我试图从另一个组件中更改routes.js中路由的值。我希望能够从组件中添加文件routes.js中的删除物理数组。任何帮助都将不胜感激。
import Shop from "examples/Icons/Shop";
// import Office from "examples/Icons/Office";
const routes = [
{
type: "collapse",
name: "Our Mission",
key: "dashboards",
icon: <Shop size="12px" />,
collapse: [
{
name: "Ways We can Help",
key: "default",
route: "/dashboards/default",
component: Default,
},
{
name: "How It Works",
key: "automotive",
route: "/dashboards/automotive",
component: Automotive,
},
{
name: "Who We Are",
key: "smart-home",
route: "/dashboards/smart-home",
component: SmartHome,
},
],
},
{ type: "title", title: " ", key: "space1" },
{
type: "collapse",
name: "Services",
key: "services",
icon: <Shop size="12px" />,
href: "https://github.com/creativetimofficial/ct-soft-ui-dashboard-pro-material-ui/blob/main/CHANGELOG.md",
component: Default,
noCollapse: true,
},
];
export default routes;访问routes.js的组件
import routes from "../../../routes";
const loggedroutes = [
{
type: "collapse",
name: "Profile",
key: "profile",
icon: <CgProfile size="12px" color="blue" />,
route: "/dashboards/Default",
collapse: [],
},
{
type: "collapse",
name: "Calendar",
key: "calendar",
component: link,
route: "/dashboards/Default",
icon: <GoCalendar size="12px" color="blue" />,
collapse: [],
},
]
routes = loggedinroutes;我想更改routes.js中的数据以匹配数组日志路径
发布于 2022-01-13 21:11:38
好的,不太清楚你在做什么,我收集了一个快速的沙箱,我将如何做这件事。
https://codesandbox.io/s/hopeful-shirley-q9mhz?file=/src/routes.js
基本上,我将使用基于单击/state/page query/etc按钮的逻辑,并通过一个函数来动态加载导航条中的路由。在app.js文件中,您可以看到如何通过单击按钮使用useState()钩子来动态加载路由。
我相信有一个更优雅的方式来完成这一点,但我希望这能让你朝着正确的方向前进!
https://stackoverflow.com/questions/70702469
复制相似问题