import { Routing } from '@singularsystems/neo-core'; import React from 'react'; import { IRouteParameter } from "./IRouteParameter"; interface INamedRouteParameter extends IRouteParameter { name: string; } export interface IProcessedRoute extends Routing.IRoute { /** Path with all parameters replaced by their default values. */ defaultPath: string; /** Route params in order, excluding query parameters. */ routeParams: INamedRouteParameter[]; queryParams: INamedRouteParameter[]; /** The path split into segments, including parameter segments. */ segments: RouteSegment[]; /** The number of required segments in the path for this route to match. */ requiredSegments: number; } type ParamsObject = { [index: string]: string | undefined; }; type RouteSegment = { value: string; param?: INamedRouteParameter; }; /** * A route which has matched, with its parameter values populated from the path. */ export interface IMatchedRoute { route: IProcessedRoute; /** Path used for the route match. Including parameter path values. Will not include the query string. */ path: string; /** Param values matched from the path. */ params?: ParamsObject; } export default class RouteProvider { menuRoutes: Routing.IMenuRoute[]; pureRoutes?: Routing.IRoute[] | undefined; notFoundComponent?: React.ComponentType | undefined; private basePaths; readonly allRoutes: IProcessedRoute[]; /** * Creates a route provider which provides a list of flattened routes. * @param menuRoutes Routes which appear on the main menu. * @param pureRoutes Routes which don't have a menu item. * @param notFoundComponent Component to render when the url doesn't match any of the above routes. */ constructor(menuRoutes: Routing.IMenuRoute[], pureRoutes?: Routing.IRoute[] | undefined, notFoundComponent?: React.ComponentType | undefined); /** Gets the raw route path the component is bound to. If the component is bound to multiple paths, the first path is returned. */ getPathForComponent(component: any): string | undefined; /** Gets the route the component is bound to. If the component is bound to multiple routes, the first route is returned. */ getRouteForComponent(component: any): IProcessedRoute | undefined; private flatten; /** * Create a copy of the route info, and process it. * Adds route parameters extracted from the component static params object. */ private processRoute; } export {};