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, Outlet,
redirect, redirect,
RouterProvider, RouterProvider,
createHashHistory,
} from '@tanstack/react-router' } from '@tanstack/react-router'
// import { TanStackRouterDevtools } from '@tanstack/router-devtools' // import { TanStackRouterDevtools } from '@tanstack/router-devtools'
import { memo, useEffect, useRef } from 'react' import { memo, useEffect, useRef } from 'react'
@ -47,12 +48,12 @@ export const queryClient = new QueryClient({
const rootRoute = createRootRouteWithContext<IRootContext>()({ const rootRoute = createRootRouteWithContext<IRootContext>()({
component: () => ( component: () => (
<>
<FetchLoading/>
<Outlet/>
<DevTools/>
{/*<TanStackRouterDevtools position={'bottom-right'}/>*/}
</>
<>
<FetchLoading/>
<Outlet/>
<DevTools/>
{/*<TanStackRouterDevtools position={'bottom-right'}/>*/}
</>
), ),
beforeLoad: ({ location }) => { beforeLoad: ({ location }) => {
if (location.pathname === '/') { if (location.pathname === '/') {
@ -251,31 +252,31 @@ const generateDynamicRoutes = (menuData: MenuItem[], parentRoute: AnyRoute) => {
} }
const routeTree = rootRoute.addChildren( 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) generateDynamicRoutes(menuData ?? [], layoutAuthRoute)
const hashHistory = createHashHistory()
const router = createRouter({ const router = createRouter({
routeTree, routeTree,
history: hashHistory,
context: { queryClient, menuData: [] }, context: { queryClient, menuData: [] },
defaultPreload: 'intent', defaultPreload: 'intent',
defaultPendingComponent: () => <Loading loading={true} delay={300}/> defaultPendingComponent: () => <Loading loading={true} delay={300}/>
@ -310,9 +314,9 @@ export const RootProvider = memo((props: { context: Partial<IRootContext> }) =>
return ( 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