UNPKG

@vaadin/hilla-file-router

Version:

Hilla file-based router

77 lines (76 loc) 2.76 kB
import { type ComponentType } from "react"; import { type RouteObject } from "react-router"; import type { AgnosticRoute, RouterBuildOptions, RouterConfiguration, ViewConfig } from "../types.js"; interface RouteBase { path?: string; children?: readonly this[]; } export type RouteList = readonly RouteObject[]; export type WritableRouteList = RouteObject[]; export type RouteTransformerOptions<T> = Readonly<{ children?: RouteList original?: RouteObject overriding?: T dupe: boolean }>; export type RouteTransformer<T> = (opts: RouteTransformerOptions<T>) => RouteObject | undefined; /** * A builder for creating a Vaadin-specific router for React with * authentication and server routes support. */ export declare class RouterConfigurationBuilder { #private; /** * Adds the given routes to the current list of routes. All the routes are * deeply merged to preserve the path uniqueness. * * @param routes - A list of routes to add to the current list. */ withReactRoutes(routes: RouteList): this; /** * Adds the given file routes to the current list of routes. All the routes * are transformed to React RouterObjects and deeply merged to preserve the * path uniqueness. * * @param routes - A list of routes to add to the current list. */ withFileRoutes(routes: readonly AgnosticRoute[]): this; /** * Adds the given server route element to each branch of the current list of * routes. * * @param component - The React component to add to each branch of the * current list of routes. * @param config - An optional configuration that will be applied to * each fallback component. */ withFallback(component: ComponentType, config?: ViewConfig): this; /** * Adds the layoutComponent as the parent layout to views with the flowLayouts ViewConfiguration set. * * @param layoutComponent - layout component to use, usually Flow */ withLayout(layoutComponent: ComponentType): this; /** * Protects all the routes that require authentication. For more details see * {@link @vaadin/hilla-react-auth#protectRoutes} function. * * @param redirectPath - the path to redirect to if the route is protected * and the user is not authenticated. */ protect(redirectPath?: string): this; /** * Deeply updates the current list of routes with the given routes merging * them in process. * * @param routes - A list of routes to merge with the current list. * @param callback - A callback to transform the routes during the merge. */ update(routes: undefined, callback: RouteTransformer<undefined>): this; update<T extends RouteBase>(routes: readonly T[], callback?: RouteTransformer<T>): this; /** * Builds the router with the current list of routes. */ build(options?: RouterBuildOptions): RouterConfiguration; } export {};