Skip to content

Commit

Permalink
allow for specifying exports with use property
Browse files Browse the repository at this point in the history
  • Loading branch information
rossipedia committed Jan 8, 2023
1 parent aecdd57 commit 0ff9113
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/react-router-dom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1241,18 +1241,23 @@ export function createModuleRoutes(
}
const { module: moduleFactory, children, ...restOfRoute } = route;

let use: NonNullable<ModuleRouteObject["use"]> =
"use" in route && Array.isArray(route.use)
? route.use
: ["default", "loader", "action", "ErrorBoundary"];

let element: RouteObject["element"];
if ("element" in route) {
element = route.element;
} else {
} else if (use.includes("default")) {
let Component = React.lazy(moduleFactory);
element = <Component />;
}

let loader: RouteObject["loader"];
if ("loader" in route) {
loader = route.loader;
} else {
} else if (use.includes("loader")) {
loader = async (args) => {
const mod = await moduleFactory();
return typeof mod.loader === "function" ? mod.loader(args) : null;
Expand Down Expand Up @@ -1313,11 +1318,13 @@ function ModuleRoutePassthroughErrorBoundary() {

export interface ModuleNonIndexRouteObject extends NonIndexRouteObject {
module?: ModuleRouteFactory;
use?: readonly (keyof ModuleRouteModule)[];
children: (ModuleRouteObject | RouteObject)[];
}

export interface ModuleIndexRouteObject extends IndexRouteObject {
module?: ModuleRouteFactory;
use?: readonly (keyof ModuleRouteModule)[];
children?: undefined;
}

Expand Down

0 comments on commit 0ff9113

Please sign in to comment.