赞
踩
选中一个二级菜单节点的时候,刷新页面的时候应该保持用户之前的选中状态,并且二级菜单展开项应该默认展开。
刷新页面选中应该不会改变,以下代码可以直接实现
Router/index.js
- import React, { lazy } from "react"
- //重定向
- import { Navigate } from "react-router-dom"
-
- import Home from "@/view/Home"
- //路由懒加载
- const Page1 = lazy(() => import("@/components/Page1/index"))
- const Page2 = lazy(() => import("@/components/Page2/index"))
- const Page301 = lazy(() => import("@/components/Page31/index"))
-
-
-
- //懒加载 提成一个公共函数,规定类型,只需调用就可以了
- const Loading = (component: JSX.Element) => {
- return (
- <React.Suspense fallback={<div>Loading...</div>}>
- {component}
- </React.Suspense>
- )
- }
-
-
- const routes = [
- {
- path: '/',
- element: <Navigate to