import * as React from "react"; import { ReactNode } from "react"; import { RouteProps } from "react-router"; interface RouteOptions extends Omit { layer?: string; /** * Generate a key to be added to the Component. * - `match_path`: Use the match path as the key - the Component will be recreated whenever the matched segment of the path changes. */ keyBy?: 'match_path' | ((props: any) => string); } interface RenderInfo { element: ReactNode; always_render?: boolean; } declare class RouteEntry { constructor(path: string, options: RouteOptions, parent?: RouteEntry); readonly relativePath: string; readonly options: RouteOptions; readonly parent: RouteEntry; private subEntries; private addEntry; get layer(): any; private _path; get path(): string; get hasComponent(): boolean; protected getAllLayers(layerSet?: Set): Set; protected internalRenderLayer(target_layer: string): RenderInfo; renderLayerToRoutes(layer?: string): React.ReactNode; renderRouteLayers(layers: string[]): Record; renderAllRouteLayers(): Record; } /** * Declaratively build React Router Routes. * * Adds the following features: * - If a Route on a branch uses `children` (indicating to React Router that it should _always_ render), * all parent routes will be converted to use `children` as well, so that, regardless of where it is used, * it will always render. Ideal for transitioning Modal, Trays, and such. * - Route "layers". Allows optionally specifying a layer when specifying a route. * This allows routes to be part of the same tree (and thus inherit relative paths), but to be used in different places. * An example of how this can be used for Modals is included below. * * **Example Usage:** * ```javascript * const ROUTES = route('/', {}, () => { * route('sub/', sub_routes) * route('test_page/', { component: TestPage }) * route('test_modal/', { component: TestModal, layer: 'modal' }) * }) * const sub_routes = () => { * route('new/', { component: CreatePage }); * } * ``` * * **Modal Example:** * ```javascript * const NamedLocationContext = createContext>({}) * export function useNamedLocation(name: string) { * const ctx = useContext(NamedLocationContext); * return useObserver(() => ctx[name]); * } * export const NamedLocationRoute: React.SFC = ({ name, ...pass }) => { * const loc = useNamedLocation(name); * return * } * export function ModalSwitch({ children }) { * const location = useLocation(); * const background = location.state && location.state.background; * * const backgroundLocation = background || location; * const namedLocations = useAsObservableSource({ * modal: background ? location : null, * }); * * return ( * * * {children} * * * ); * } * const ROUTE_LAYERS = ROUTES.renderAllRouteLayers(); * const WRAPPED_ROUTES = Object.entries(ROUTE_LAYERS).map(([layer, routes]) => { * if (name == 'default') return routes; * return * }) * const RoutesComponent = () => { * return * } * ``` * * @param path * @param block */ export declare function route(path: string, block: () => void): RouteEntry; export declare function route(path: string, options: RouteOptions, block?: () => void): RouteEntry; export {};