Declarative routing for React Native applications with native-specific components and deep linking support
npx @tessl/cli install tessl/npm-react-router-native@6.30.0React Router Native provides declarative routing for React Native applications. It extends React Router with native-specific components and hooks, enabling URL-based navigation patterns in mobile apps with support for deep linking, hardware back button integration, and touch-based navigation.
npm install react-router-native react-router react react-native @ungap/url-search-paramsimport { NativeRouter, Link, Routes, Route } from "react-router-native";
import { useSearchParams, useDeepLinking, useLinkPressHandler } from "react-router-native";For CommonJS:
const { NativeRouter, Link, Routes, Route } = require("react-router-native");import React from "react";
import { View, Text } from "react-native";
import { NativeRouter, Routes, Route, Link } from "react-router-native";
function App() {
return (
<NativeRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
</NativeRouter>
);
}
function Home() {
return (
<View>
<Text>Home Screen</Text>
<Link to="/about">
<Text>Go to About</Text>
</Link>
</View>
);
}
function About() {
return (
<View>
<Text>About Screen</Text>
<Link to="/">
<Text>Go to Home</Text>
</Link>
</View>
);
}React Router Native is built around several key components:
NativeRouter component provides memory-based routing for React Native appsLink component built on TouchableHighlight for native touch interactionsEssential React Native routing components including the main router and navigation links optimized for mobile touch interactions.
interface NativeRouterProps extends MemoryRouterProps {}
function NativeRouter(props: NativeRouterProps): JSX.Element;
interface LinkProps extends TouchableHighlightProps {
children?: React.ReactNode;
onPress?: (event: GestureResponderEvent) => void;
relative?: RelativeRoutingType;
replace?: boolean;
state?: any;
to: To;
}
function Link(props: LinkProps): JSX.Element;Native-specific hooks for custom navigation behavior, hardware integration, and deep linking support.
function useLinkPressHandler(
to: To,
options?: {
replace?: boolean;
state?: any;
relative?: RelativeRoutingType;
}
): (event: GestureResponderEvent) => void;
function useDeepLinking(): void;
function useHardwareBackButton(): void;
function useAndroidBackButton(): void;Enhanced URLSearchParams functionality adapted for React Native applications with mobile-optimized parameter handling.
function useSearchParams(
defaultInit?: URLSearchParamsInit
): [URLSearchParams, SetURLSearchParams];
function createSearchParams(init?: URLSearchParamsInit): URLSearchParams;
type SetURLSearchParams = (
nextInit?:
| URLSearchParamsInit
| ((prev: URLSearchParams) => URLSearchParamsInit),
navigateOpts?: NavigateOptions
) => void;
type URLSearchParamsInit =
| string
| ParamKeyValuePair[]
| Record<string, string | string[]>
| URLSearchParams;Complete re-export of React Router components for building declarative route structures in React Native applications.
function MemoryRouter(props: MemoryRouterProps): JSX.Element;
function Routes(props: RoutesProps): JSX.Element;
function Route(props: RouteProps): JSX.Element;
function Navigate(props: NavigateProps): JSX.Element;
function Outlet(props: OutletProps): JSX.Element;Complete re-export of React Router hooks for accessing navigation state, route data, and programmatic navigation.
function useNavigate(): NavigateFunction;
function useLocation(): Location;
function useParams(): Params;
function useNavigationType(): NavigationType;
function useMatch(pattern: PathPattern): PathMatch | null;Complete re-export of React Router utility functions for path manipulation, route creation, and data handling.
function createMemoryRouter(routes: RouteObject[], opts?: RouterOptions): Router;
function createPath(partialPath: Partial<Path>): string;
function generatePath(pattern: string, params?: Params): string;
function matchPath(pattern: PathPattern, pathname: string): PathMatch | null;interface NativeRouterProps extends MemoryRouterProps {}
interface LinkProps extends TouchableHighlightProps {
children?: React.ReactNode;
onPress?: (event: GestureResponderEvent) => void;
relative?: RelativeRoutingType;
replace?: boolean;
state?: any;
to: To;
}
type ParamKeyValuePair = [string, string];
type URLSearchParamsInit =
| string
| ParamKeyValuePair[]
| Record<string, string | string[]>
| URLSearchParams;
type SetURLSearchParams = (
nextInit?:
| URLSearchParamsInit
| ((prev: URLSearchParams) => URLSearchParamsInit),
navigateOpts?: NavigateOptions
) => void;All React Router types are re-exported, including:
RouteObject, IndexRouteObject, NonIndexRouteObject, RouteMatchNavigateFunction, NavigateOptions, NavigationType, LocationRouteProps, RoutesProps, OutletProps, NavigatePropsTo, Params, PathMatch, PathPattern, RelativeRoutingTypeLoaderFunction, ActionFunction, Fetcher, ErrorResponseSee React Router documentation for complete type definitions.