Fix home page crashing when using react-router lazy import
This commit is contained in:
@@ -16,6 +16,8 @@ export interface AsyncRoute {
|
||||
page?: string
|
||||
/** The page type used to load the correct page element. */
|
||||
type?: AsyncRouteType
|
||||
/** Override for pages that don't support lazy importing */
|
||||
Component?: React.ComponentType | null;
|
||||
}
|
||||
|
||||
const importPage = (page: string, type: AsyncRouteType) => {
|
||||
@@ -29,12 +31,23 @@ const importPage = (page: string, type: AsyncRouteType) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const toAsyncPageRoute = ({ path, page, type = AsyncRouteType.Stable }: AsyncRoute): RouteObject => ({
|
||||
export const toAsyncPageRoute = ({
|
||||
path,
|
||||
lazy: async () => {
|
||||
const { default: Component } = await importPage(page ?? path, type);
|
||||
return {
|
||||
Component
|
||||
};
|
||||
page,
|
||||
Component,
|
||||
type = AsyncRouteType.Stable
|
||||
}: AsyncRoute): RouteObject => {
|
||||
if (Component) {
|
||||
return { path, Component };
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
path,
|
||||
lazy: async () => {
|
||||
const { default: Page } = await importPage(page ?? path, type);
|
||||
return {
|
||||
Component: Page
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user