UNPKG

@vaadin/hilla-file-router

Version:

Hilla file-based router

106 lines (105 loc) 3.62 kB
import type { RouteObject } from "react-router"; import type { Module, RouteModule } from "../../types.js"; /** * A function type that modifies the current route tree. * * @param routes - The current route tree to process. * @returns An optional readonly array of RouteObject instances after modification */ export type RouteTreeModifier = (routes: readonly RouteObject[] | undefined) => readonly RouteObject[] | undefined; /** * A route-like object that can be used in the route tree. */ export interface RouteLike { path?: string; children?: readonly this[]; } /** * Options for transforming a route object within the route configuration builder. * * @typeParam T - The type of the override object. */ export type RouteTransformerOptions<T extends RouteLike> = Readonly<{ /** * Array of child route objects. If omitted, the route is considered leaf. */ children?: readonly RouteObject[] /** * The original route object to transform. */ original?: RouteObject /** * Override object to apply custom transformations. */ override?: T /** * Indicates whether the route is a duplicate. Used to handle cases where * multiple routes may share the same path. */ dupe?: boolean }>; export type RouteTransformer<T extends RouteLike = RouteLike> = (opts: RouteTransformerOptions<T>) => RouteObject | undefined; /** * 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 declare function isReactRouteModule(module: Module): module is RouteModule; /** * 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 declare function createRouteKey<T extends RouteLike>(route: T): string; /** * 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 declare const RouteHandleFlag: { readonly FLOW_LAYOUT: "flowLayout" readonly IGNORE_FALLBACK: "ignoreFallback" readonly SKIP_LAYOUTS: "skipLayouts" }; export type RouteHandleFlag = (typeof RouteHandleFlag)[keyof typeof RouteHandleFlag]; /** * 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 declare function getHandleFlag<T extends RouteHandleFlag>(route: RouteObject, flag: T): boolean | undefined; /** * Determines whether the given route object represents an index route. * * @param route - The route object to check. */ export declare function isIndexRoute(route: RouteObject): boolean; /** * Determines whether the given route is optional based on its path. * * @param route - The route object to check. */ export declare function isOptionalRoute(route: RouteObject): boolean; /** * Determines whether the given route is a wildcard route. * * @param route - The route object to check. */ export declare function isWildcardRoute(route: RouteObject): boolean;