import type { ReactNode } from 'react'; import type { TextProps, GestureResponderEvent } from 'react-native'; export declare namespace ExpoRouter { type StaticRoutes = string; type DynamicRouteTemplate = never; export type RelativePathString = `./${string}` | `../${string}` | '..'; export type AbsoluteRoute = DynamicRouteTemplate | StaticRoutes; export type ExternalPathString = `${string}:${string}`; export type ExpoRouterRoutes = DynamicRouteTemplate | StaticRoutes | RelativePathString; export type AllRoutes = ExpoRouterRoutes | ExternalPathString; /**************** * Route Utils * ****************/ type SearchOrHash = `?${string}` | `#${string}`; export type UnknownInputParams = Record; type UnknownOutputParams = Record; /** * Return the name of a route parameter * '[test]' -> 'test' * 'test' -> never * '[...test]' -> '...test' */ type IsParameter = Part extends `[${infer ParamName}]` ? ParamName : never; /** * Return a union of all raw parameter names. If there are no names return never * * This differs from ParameterNames as it returns the `...` for catch all parameters * * /[test] -> 'test' * /[abc]/[...def] -> 'abc'|'...def' */ type ParameterNames = Path extends `${infer PartA}/${infer PartB}` ? IsParameter | ParameterNames : IsParameter; /** * Returns all segments of a route. * * /(group)/123/abc/[id]/[...rest] -> ['(group)', '123', 'abc', '[id]', '[...rest]' */ type RouteSegments = Path extends `${infer PartA}/${infer PartB}` ? PartA extends '' | '.' ? [...RouteSegments] : [PartA, ...RouteSegments] : Path extends '' ? [] : [Path]; type AllUngroupedRoutes = Path extends `(${infer PartA})/${infer PartB}` ? `(${PartA})/${AllUngroupedRoutes}` | AllUngroupedRoutes : Path; /** * Returns a Record of the routes parameters as strings and CatchAll parameters * * There are two versions, input and output, as you can input 'string | number' but * the output will always be 'string' * * /[id]/[...rest] -> { id: string, rest: string[] } * /no-params -> {} */ export type InputRouteParams = { [Key in ParameterNames as Key extends `...${infer Name}` ? Name : Key]: Key extends `...${string}` ? (string | number)[] : string | number; } & UnknownInputParams; type OutputRouteParams = { [Key in ParameterNames as Key extends `...${infer Name}` ? Name : Key]: Key extends `...${string}` ? string[] : string; } & UnknownOutputParams; /** * Returns the search parameters for a route. */ export type SearchParams = T extends DynamicRouteTemplate ? OutputRouteParams : T extends StaticRoutes ? never : UnknownOutputParams; /********* * Href * *********/ /** * The main routing type for Expo Router. Includes all available routes with strongly typed parameters. * * Allows for static routes, relative paths, external paths, dynamic routes, and the dynamic route provided as a static string */ export type Href = StringRouteToType | RelativePathString | ExternalPathString> | DynamicRouteTemplateToString | DynamicRouteObject; type StringRouteToType = T | `${T}${SearchOrHash}` | { pathname: T; params?: UnknownInputParams | never; }; type DynamicRouteTemplateToString = Path extends `${infer PartA}/${infer PartB}` ? `${PartA extends `[${string}]` ? string : PartA}/${DynamicRouteTemplateToString}` : Path extends `[${string}]` ? string : Path; type DynamicRouteObject = T extends DynamicRouteTemplate ? { pathname: T; params: InputRouteParams; } : never; /*********************** * Expo Router Exports * ***********************/ export type Router = { /** Go back in the history. */ back: () => void; /** If there's history that supports invoking the `back` function. */ canGoBack: () => boolean; /** Navigate to the provided href using a push operation if possible. */ push: (href: Href) => void; /** Navigate to the provided href. */ navigate: (href: Href) => void; /** Navigate to route without appending to the history. */ replace: (href: Href) => void; /** Navigate to the provided href using a push operation if possible. */ dismiss: (count?: number) => void; /** Navigate to first screen within the lowest stack. */ dismissAll: () => void; /** If there's history that supports invoking the `dismiss` and `dismissAll` function. */ canDismiss: () => boolean; /** Update the current route query params. */ setParams: (params?: T extends '' ? Record : InputRouteParams) => void; }; /** The imperative router. */ export const router: Router; /************ * * ************/ export interface WebAnchorProps { /** * **Web only:** Specifies where to open the `href`. * * - **_self**: the current tab. * - **_blank**: opens in a new tab or window. * - **_parent**: opens in the parent browsing context. If no parent, defaults to **_self**. * - **_top**: opens in the highest browsing context ancestor. If no ancestors, defaults to **_self**. * * This property is passed to the underlying anchor (``) tag. * * @default '_self' * * @example * Go to Expo in new tab */ target?: '_self' | '_blank' | '_parent' | '_top' | (string & object); /** * **Web only:** Specifies the relationship between the `href` and the current route. * * Common values: * - **nofollow**: Indicates to search engines that they should not follow the `href`. This is often used for user-generated content or links that should not influence search engine rankings. * - **noopener**: Suggests that the `href` should not have access to the opening window's `window.opener` object, which is a security measure to prevent potentially harmful behavior in cases of links that open new tabs or windows. * - **noreferrer**: Requests that the browser not send the `Referer` HTTP header when navigating to the `href`. This can enhance user privacy. * * The `rel` property is primarily used for informational and instructive purposes, helping browsers and web * crawlers make better decisions about how to handle and interpret the links on a web page. It is important * to use appropriate `rel` values to ensure that links behave as intended and adhere to best practices for web * development and SEO (Search Engine Optimization). * * This property is passed to the underlying anchor (``) tag. * * @example * Go to Expo */ rel?: string; /** * **Web only:** Specifies that the `href` should be downloaded when the user clicks on the link, * instead of navigating to it. It is typically used for links that point to files that the user should download, * such as PDFs, images, documents, etc. * * The value of the `download` property, which represents the filename for the downloaded file. * This property is passed to the underlying anchor (``) tag. * * @example * Download image */ download?: string; } export interface LinkProps extends Omit, WebAnchorProps { /** Path to route to. */ href: Href; /** Forward props to child component. Useful for custom buttons. */ asChild?: boolean; /** Should replace the current route without adding to the history. */ replace?: boolean; /** Should push the current route */ push?: boolean; /** On web, this sets the HTML `class` directly. On native, this can be used with CSS interop tools like Nativewind. */ className?: string; onPress?: (e: React.MouseEvent | GestureResponderEvent) => void; } export interface LinkComponent { (props: React.PropsWithChildren): JSX.Element; /** Helper method to resolve an Href object into a string. */ resolveHref: (href: Href) => string; } /** * Component to render link to another route using a path. * Uses an anchor tag on the web. * * @param props.href Absolute path to route (e.g. \`/feeds/hot\`). * @param props.replace Should replace the current route without adding to the history. * @param props.asChild Forward props to child component. Useful for custom buttons. * @param props.children Child elements to render the content. * @param props.className On web, this sets the HTML \`class\` directly. On native, this can be used with CSS interop tools like Nativewind. */ export const Link: LinkComponent; /** Redirects to the href as soon as the component is mounted. */ export const Redirect: (props: React.PropsWithChildren<{ href: Href; }>) => ReactNode; export type Redirect = typeof Redirect; /** * Hooks */ export function useRouter(): Router; /** * Returns the URL search parameters for the contextually focused route. e.g. \`/acme?foo=bar\` -> \`{ foo: "bar" }\`. * This is useful for stacks where you may push a new screen that changes the query parameters. * * To observe updates even when the invoking route is not focused, use \`useGlobalSearchParams()\`. * @see \`useGlobalSearchParams\` */ export function useLocalSearchParams(): TParams extends AllRoutes ? SearchParams : TParams; export function useSearchParams(): TParams extends AllRoutes ? SearchParams : TParams; /** * Get the globally selected query parameters, including dynamic path segments. This function will update even when the route is not focused. * Useful for analytics or other background operations that don't draw to the screen. * * When querying search params in a stack, opt-towards using \`useLocalSearchParams\` as these will only * update when the route is focused. * * @see \`useLocalSearchParams\` */ export function useGlobalSearchParams(): T extends AllRoutes ? SearchParams : T; /** * Get a list of selected file segments for the currently selected route. Segments are not normalized, so they will be the same as the file path. e.g. /[id]?id=normal -> ["[id]"] * * \`useSegments\` can be typed using an abstract. * Consider the following file structure, and strictly typed \`useSegments\` function: * * \`\`\`md * - app * - [user] * - index.js * - followers.js * - settings.js * \`\`\` * This can be strictly typed using the following abstract: * * \`\`\`ts * const [first, second] = useSegments<['settings'] | ['[user]'] | ['[user]', 'followers']>() * \`\`\` */ export function useSegments | RelativePathString>(): T extends AbsoluteRoute ? RouteSegments : T extends string ? string[] : T; export {}; } //# sourceMappingURL=router.d.ts.map