UNPKG

next

Version:

The React Framework

82 lines (81 loc) 3.26 kB
import { type SegmentParam } from '../utils/get-segment-param'; import { type InterceptionMarker } from '../utils/interception-routes'; export type RouteGroupAppRouteSegment = { type: 'route-group'; name: string; /** * If present, this segment has an interception marker prefixing it. */ interceptionMarker?: InterceptionMarker; }; export type ParallelRouteAppRouteSegment = { type: 'parallel-route'; name: string; /** * If present, this segment has an interception marker prefixing it. */ interceptionMarker?: InterceptionMarker; }; export type StaticAppRouteSegment = { type: 'static'; name: string; /** * If present, this segment has an interception marker prefixing it. */ interceptionMarker?: InterceptionMarker; }; export type DynamicAppRouteSegment = { type: 'dynamic'; name: string; param: SegmentParam; /** * If present, this segment has an interception marker prefixing it. */ interceptionMarker?: InterceptionMarker; }; /** * Represents a single segment in a route path. * Can be either static (e.g., "blog") or dynamic (e.g., "[slug]"). */ export type AppRouteSegment = StaticAppRouteSegment | DynamicAppRouteSegment | RouteGroupAppRouteSegment | ParallelRouteAppRouteSegment; export type NormalizedAppRouteSegment = StaticAppRouteSegment | DynamicAppRouteSegment; export declare function parseAppRouteSegment(segment: string): AppRouteSegment | null; export type AppRoute = { normalized: boolean; pathname: string; segments: AppRouteSegment[]; dynamicSegments: DynamicAppRouteSegment[]; interceptionMarker: InterceptionMarker | undefined; interceptingRoute: AppRoute | undefined; interceptedRoute: AppRoute | undefined; }; export type NormalizedAppRoute = Omit<AppRoute, 'normalized' | 'segments'> & { normalized: true; segments: NormalizedAppRouteSegment[]; }; export declare function isNormalizedAppRoute(route: InterceptionAppRoute): route is NormalizedInterceptionAppRoute; export type InterceptionAppRoute = Omit<AppRoute, 'interceptionMarker' | 'interceptingRoute' | 'interceptedRoute'> & { interceptionMarker: InterceptionMarker; interceptingRoute: AppRoute; interceptedRoute: AppRoute; }; export type NormalizedInterceptionAppRoute = Omit<InterceptionAppRoute, 'normalized' | 'segments' | 'interceptionMarker' | 'interceptingRoute' | 'interceptedRoute'> & { normalized: true; segments: NormalizedAppRouteSegment[]; interceptionMarker: InterceptionMarker; interceptingRoute: NormalizedAppRoute; interceptedRoute: NormalizedAppRoute; }; export declare function isInterceptionAppRoute(route: NormalizedAppRoute): route is NormalizedInterceptionAppRoute; /** * Parse an app route that has been fully normalized (no @slot or () * group segments). Throws if either is present. */ export declare function parseNormalizedAppRoute(pathname: string): NormalizedAppRoute; /** * Parse an app route that may contain @slot segments but not () * group segments. Slot segments are preserved as parallel-route * type segments so callers can distinguish routes in different * parallel slots. */ export declare function parseAppRouteWithSlots(pathname: string): AppRoute;