UNPKG

@vaadin/hilla-file-router

Version:

Hilla file-based router

25 lines (24 loc) 1.2 kB
import { type ComponentType } from "react"; import type { RouteObject } from "react-router"; /** * Splits out the server-side route tree based on the {@link ViewConfiguration.flowLayout} * flag, and wraps them in the provided server layout component. * * @remarks * Internally, routes are categorized into three groups: * - **Server routes**: Routes with `flowLayout` flag explicitly set to `true`, * or routes whose children have the flag enabled. * - **Client routes**: Routes with `flowLayout` flag explicitly set to `false`, * or routes with client-side children. * - **Unknown routes**: Routes without explicit flags that inherit behavior * from their parent context. * * Server routes get the {@link RouteHandleFlag.IGNORE_FALLBACK} flag set to * prevent fallback route interference. Client routes are preserved as-is. * * @param originalRoutes - The current route tree to process. * @param component - The layout component to wrap around server routes. * * @returns A new route configuration with the layout applied to server routes. */ export default function mergeLayout(originalRoutes: readonly RouteObject[] | undefined, component: ComponentType): readonly RouteObject[] | undefined;