UNPKG

@vaadin/hilla-file-router

Version:

Hilla file-based router

25 lines (24 loc) 1.29 kB
import type { RouteObject } from "react-router"; import { type RouteLike, type RouteTransformer } from "./utils.js"; /** * Updates a route tree by merging, transforming, or replacing route objects. * * This function takes an existing route tree and a new tree of routes, then * applies a transformer recursively to produce an updated route tree. The * update strategy depends on the presence of the original and added trees: * - If both `existingRoutes` and `tree` are provided, they are recursively * merged them using the provided transformer. * - If only `existingRoutes` is provided, only the original routes are * transformed. * - If only `tree` is provided, it is transformed and used as a new route tree. * * @typeParam T - The type of the route-like objects in the tree. * * @param existingRoutes - The current route tree. * @param tree - The new tree of route-like objects to merge recursively. * @param transformer - A function to transform route objects. * * @returns The updated route tree as an array of `RouteObject`, or `undefined` * if no routes are present. */ export declare function mergeRouteTrees<T extends RouteLike>(existingRoutes: readonly RouteObject[] | undefined, tree: readonly T[] | undefined, transformer?: RouteTransformer<T>): readonly RouteObject[] | undefined;