fix: loading only outlet instead of whole page for child subroutes
This commit is contained in:
@@ -4,9 +4,10 @@ import { appRoutes } from '@/routes/config';
|
|||||||
import { Outlet, useLocation } from 'react-router-dom';
|
import { Outlet, useLocation } from 'react-router-dom';
|
||||||
import { Box, useMediaQuery, useTheme } from '@mui/material';
|
import { Box, useMediaQuery, useTheme } from '@mui/material';
|
||||||
import { Header } from './Header';
|
import { Header } from './Header';
|
||||||
import { useState } from 'react';
|
import { Suspense, useState } from 'react';
|
||||||
import { Toolbar } from './Toolbar';
|
import { Toolbar } from './Toolbar';
|
||||||
import { useAuth } from '@/hooks/useAuth';
|
import { useAuth } from '@/hooks/useAuth';
|
||||||
|
import { Loading } from '../routes/Loading';
|
||||||
|
|
||||||
export const Layout = () => {
|
export const Layout = () => {
|
||||||
const navItemConfigs = buildNavItems(appRoutes);
|
const navItemConfigs = buildNavItems(appRoutes);
|
||||||
@@ -53,7 +54,9 @@ export const Layout = () => {
|
|||||||
overflowInline: 'auto',
|
overflowInline: 'auto',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Outlet />
|
<Suspense fallback={<Loading />}>
|
||||||
|
<Outlet />
|
||||||
|
</Suspense>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { Suspense, type ReactNode } from 'react';
|
import { type ReactNode } from 'react';
|
||||||
import { createBrowserRouter, type RouteObject } from 'react-router-dom';
|
import { createBrowserRouter, type RouteObject } from 'react-router-dom';
|
||||||
import { appRoutes, type RouteConfig } from './config';
|
import { appRoutes, type RouteConfig } from './config';
|
||||||
import { ProtectedRoute } from '@/components/routes/ProtectedRoute';
|
import { ProtectedRoute } from '@/components/routes/ProtectedRoute';
|
||||||
import { Loading } from '@/components/routes/Loading';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A recursive function to map our custom route config to the format
|
* A recursive function to map our custom route config to the format
|
||||||
@@ -10,15 +9,9 @@ import { Loading } from '@/components/routes/Loading';
|
|||||||
*/
|
*/
|
||||||
function mapRoutes(routes: RouteConfig[]): RouteObject[] {
|
function mapRoutes(routes: RouteConfig[]): RouteObject[] {
|
||||||
return routes.map((route) => {
|
return routes.map((route) => {
|
||||||
// Start with the base element, wrapped in Suspense for lazy loading
|
// Remove the suspense from here and move to layout outlet
|
||||||
let element: ReactNode = (
|
// Avoid loading layout for rendering different children
|
||||||
<Suspense fallback={<Loading />}>{route.element}</Suspense>
|
let element: ReactNode = route.element;
|
||||||
);
|
|
||||||
|
|
||||||
// Conditionally wrap the element in the specified layout
|
|
||||||
// if (route.layout) {
|
|
||||||
// element = <route.layout>{element}</route.layout>;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (route.authorize) {
|
if (route.authorize) {
|
||||||
element = <ProtectedRoute>{element}</ProtectedRoute>;
|
element = <ProtectedRoute>{element}</ProtectedRoute>;
|
||||||
|
|||||||
Reference in New Issue
Block a user