UNPKG

@vaadin/hilla-file-router

Version:

Hilla file-based router

79 lines 2.39 kB
/** * Checks if the given module is a valid React route module. * * @param module - The JS module to check. * @returns True if the module is a valid React route module, false otherwise. */ export function isReactRouteModule(module) { return "default" in module && typeof module.default === "function" || "config" in module && typeof module.config === "object"; } /** * Creates a unique key for a route based on its path and children. * * @param route - The route object to create a key for. * @returns A unique key string for the route. */ export function createRouteKey(route) { return `${route.path ?? ""}-${route.children ? "n" : "i"}`; } /** * A set of flags that can be used to control the behavior of routes in the * router configuration. * * @remarks * These flags work together to control route rendering behavior: * * **Layout Control:** * - `FLOW_LAYOUT: true` - Route renders with server-side layout (Flow * component) * - `FLOW_LAYOUT: false` - Route renders without server-side layout * (client-only) * - `SKIP_LAYOUTS: true` - Route bypasses ALL layouts (overrides FLOW_LAYOUT) * * **Fallback Control:** * - `IGNORE_FALLBACK: true` - Route ignores fallback components, used * internally by {@link mergeLayout} and {@link mergeSkipLayouts} */ export const RouteHandleFlag = { FLOW_LAYOUT: "flowLayout", IGNORE_FALLBACK: "ignoreFallback", SKIP_LAYOUTS: "skipLayouts" }; /** * Retrieves a specific flag from the route's handle object. * * @param route - The route object to retrieve the flag from. * @param flag - The flag to retrieve. * @returns The value of the flag if it exists, otherwise undefined. */ export function getHandleFlag(route, flag) { if (typeof route.handle === "object" && flag in route.handle) { return route.handle[flag]; } return undefined; } /** * Determines whether the given route object represents an index route. * * @param route - The route object to check. */ export function isIndexRoute(route) { return !!route.index; } /** * Determines whether the given route is optional based on its path. * * @param route - The route object to check. */ export function isOptionalRoute(route) { return !!route.path?.includes("?"); } /** * Determines whether the given route is a wildcard route. * * @param route - The route object to check. */ export function isWildcardRoute(route) { return route.path === "*"; } //# sourceMappingURL=./utils.js.map