Browse Source

改用hash路由

main
李金 6 months ago
parent
commit
1ecf176fc7
  1. 72
      src/routes.tsx

72
src/routes.tsx

@ -20,6 +20,7 @@ import {
Outlet,
redirect,
RouterProvider,
createHashHistory,
} from '@tanstack/react-router'
// import { TanStackRouterDevtools } from '@tanstack/router-devtools'
import { memo, useEffect, useRef } from 'react'
@ -47,12 +48,12 @@ export const queryClient = new QueryClient({
const rootRoute = createRootRouteWithContext<IRootContext>()({
component: () => (
<>
<FetchLoading/>
<Outlet/>
<DevTools/>
{/*<TanStackRouterDevtools position={'bottom-right'}/>*/}
</>
<>
<FetchLoading/>
<Outlet/>
<DevTools/>
{/*<TanStackRouterDevtools position={'bottom-right'}/>*/}
</>
),
beforeLoad: ({ location }) => {
if (location.pathname === '/') {
@ -251,31 +252,31 @@ const generateDynamicRoutes = (menuData: MenuItem[], parentRoute: AnyRoute) => {
}
const routeTree = rootRoute.addChildren(
[
//非Layout
loginRoute,
emptyRoute,
//不带权限Layout
layoutNormalRoute.addChildren([
notAuthRoute,
]),
//带权限Layout
// dashboardRoute,
authRoute.addChildren(
[
layoutAuthRoute
/*.addChildren(
[
menusRoute,
departmentsRoute,
usersRoute,
rolesRoute,
]
),*/
]),
]
[
//非Layout
loginRoute,
emptyRoute,
//不带权限Layout
layoutNormalRoute.addChildren([
notAuthRoute,
]),
//带权限Layout
// dashboardRoute,
authRoute.addChildren(
[
layoutAuthRoute
/*.addChildren(
[
menusRoute,
departmentsRoute,
usersRoute,
rolesRoute,
]
),*/
]),
]
)
@ -301,8 +302,11 @@ export const RootProvider = memo((props: { context: Partial<IRootContext> }) =>
generateDynamicRoutes(menuData ?? [], layoutAuthRoute)
const hashHistory = createHashHistory()
const router = createRouter({
routeTree,
history: hashHistory,
context: { queryClient, menuData: [] },
defaultPreload: 'intent',
defaultPendingComponent: () => <Loading loading={true} delay={300}/>
@ -310,9 +314,9 @@ export const RootProvider = memo((props: { context: Partial<IRootContext> }) =>
return (
<QueryClientProvider client={queryClient}>
<RouterProvider router={router} context={{ ...props.context, menuData, queryClient }}/>
</QueryClientProvider>
<QueryClientProvider client={queryClient}>
<RouterProvider router={router} context={{ ...props.context, menuData, queryClient }}/>
</QueryClientProvider>
)
})
Loading…
Cancel
Save