UNPKG

dew-router

Version:

32 lines (31 loc) 1.41 kB
import { WebsiteRoute } from 'dew-types'; import { PathFunction } from 'path-to-regexp'; import React, { ReactNode } from 'react'; import { LinkValue, MatchedRoute, RouterLocation, RouterNavigator, StringOrStringArray, UrlParams } from './types'; export interface LocationContextValue { routes: WebsiteRoute[]; matchedRoutes: MatchedRoute[]; location: RouterLocation; navigator: RouterNavigator; query: Record<string, StringOrStringArray>; pathFnMap: Record<string, PathFunction<UrlParams>>; } export declare const LocationContext: React.Context<LocationContextValue | undefined>; export interface RouterProps { routes: WebsiteRoute[]; matchedRoutes: MatchedRoute[]; children: ReactNode; location: RouterLocation; navigator: RouterNavigator; } export declare function makePathFnMap(_routes: WebsiteRoute[]): Record<string, PathFunction<Record<string, StringOrStringArray>>>; export declare function Router({ location, routes, matchedRoutes, navigator, children, }: RouterProps): JSX.Element; export declare function useRouter(): { routes: WebsiteRoute[]; matchedRoutes: MatchedRoute[]; location: RouterLocation; query: Record<string, StringOrStringArray>; navigator: RouterNavigator; parseLink: ({ name, lang, params, query }: LinkValue) => string | null; pathFnMap: Record<string, PathFunction<Record<string, StringOrStringArray>>>; };