|
7 | 7 |
|
8 | 8 | React Router is a collection of [React components](https://reactjs.org/docs/components-and-props.html), [hooks](https://reactjs.org/docs/hooks-intro.html) and utilities that make it easy to build multi-page applications with [React](https://reactjs.org). This reference contains the function signatures and return types of the various interfaces in React Router.
|
9 | 9 |
|
10 |
| -<docs-info>Please refer to [our guides](./guides/index.md) for more in-depth usage examples of how you can use React Router to accomplish specific tasks.</docs-info> |
11 |
| - |
12 | 10 | ## Overview
|
13 | 11 |
|
14 | 12 | ### Packages
|
@@ -45,7 +43,6 @@ A few low-level pieces that we use internally are also exposed as public API, in
|
45 | 43 |
|
46 | 44 | - [`matchPath`](#matchpath) - matches a path pattern against a URL pathname
|
47 | 45 | - [`matchRoutes`](#matchroutes) - matches a set of routes against a [location](#location)
|
48 |
| -- [`createRoutesFromArray`](#createroutesfromarray) - creates a route config from a set of plain JavaScript objects |
49 | 46 | - [`createRoutesFromChildren`](#createroutesfromchildren) - creates a route config from a set of React elements (i.e. [`<Route>`](#routes-and-route) elements)
|
50 | 47 |
|
51 | 48 | ### Navigation
|
@@ -96,8 +93,8 @@ interface BrowserRouterProps {
|
96 | 93 | `<BrowserRouter window>` defaults to using the current [document's `defaultView`](https://developer.mozilla.org/en-US/docs/Web/API/Document/defaultView), but it may also be used to track changes to another's window's URL, in an `<iframe>`, for example.
|
97 | 94 |
|
98 | 95 | ```tsx
|
99 |
| -import React from "react"; |
100 |
| -import ReactDOM from "react-dom"; |
| 96 | +import * as React from "react"; |
| 97 | +import * as ReactDOM from "react-dom"; |
101 | 98 | import { BrowserRouter } from "react-router-dom";
|
102 | 99 |
|
103 | 100 | ReactDOM.render(
|
@@ -132,8 +129,8 @@ interface HashRouterProps {
|
132 | 129 | `<HashRouter window>` defaults to using the current [document's `defaultView`](https://developer.mozilla.org/en-US/docs/Web/API/Document/defaultView), but it may also be used to track changes to another window's URL, in an `<iframe>`, for example.
|
133 | 130 |
|
134 | 131 | ```tsx
|
135 |
| -import React from "react"; |
136 |
| -import ReactDOM from "react-dom"; |
| 132 | +import * as React from "react"; |
| 133 | +import * as ReactDOM from "react-dom"; |
137 | 134 | import { HashRouter } from "react-router-dom";
|
138 | 135 |
|
139 | 136 | ReactDOM.render(
|
@@ -167,7 +164,7 @@ interface NativeRouterProps extends MemoryRouterProps {}
|
167 | 164 | - `<NativeRouter initialIndex>` defaults to the last index of `props.initialEntries`
|
168 | 165 |
|
169 | 166 | ```tsx
|
170 |
| -import React from "react"; |
| 167 | +import * as React from "react"; |
171 | 168 | import { NativeRouter } from "react-router-native";
|
172 | 169 |
|
173 | 170 | function App() {
|
@@ -211,7 +208,7 @@ A `<MemoryRouter>` stores its locations internally in an array. Unlike `<Browser
|
211 | 208 | > [browsing through our tests](https://github.com/remix-run/react-router/tree/main/packages/react-router/__tests__).
|
212 | 209 |
|
213 | 210 | ```tsx
|
214 |
| -import React from "react"; |
| 211 | +import * as React from "react"; |
215 | 212 | import { create } from "react-test-renderer";
|
216 | 213 | import {
|
217 | 214 | MemoryRouter,
|
@@ -268,7 +265,7 @@ type To = Partial<Location> | string;
|
268 | 265 | A `<Link>` is an element that lets the user navigate to another page by clicking or tapping on it. In `react-router-dom`, a `<Link>` renders an accessible `<a>` element with a real `href` that points to the resource it's linking to. This means that things like right-clicking a `<Link>` work as you'd expect.
|
269 | 266 |
|
270 | 267 | ```tsx
|
271 |
| -import React from "react"; |
| 268 | +import * as React from "react"; |
272 | 269 | import { Link } from "react-router-dom";
|
273 | 270 |
|
274 | 271 | function UsersIndexPage({ users }) {
|
@@ -323,7 +320,7 @@ interface LinkProps extends TouchableHighlightProps {
|
323 | 320 | A `<Link>` is an element that lets the user navigate to another view by tapping it, similar to how `<a>` elements work in a web app. In `react-router-native`, a `<Link>` renders a `TouchableHighlight`.
|
324 | 321 |
|
325 | 322 | ```tsx
|
326 |
| -import React from "react"; |
| 323 | +import * as React from "react"; |
327 | 324 | import { View, Text } from "react-native";
|
328 | 325 | import { Link } from "react-router-native";
|
329 | 326 |
|
@@ -369,7 +366,7 @@ A `<NavLink>` is a special kind of [`<Link>`](#link) that knows whether or not i
|
369 | 366 | By default, an `active` class is added to a `<NavLink>` component when it is active. This provides the same simple styling mechanism for most users who are upgrading from v5. One difference as of `v6.0.0-beta.3` is that `activeClassName` and `activeStyle` have been removed from `NavLinkProps`. Instead, you can pass a function to either `style` or `className` that will allow you to customize the inline styling or the class string based on the component's active state.
|
370 | 367 |
|
371 | 368 | ```tsx
|
372 |
| -import React from "react"; |
| 369 | +import * as React from "react"; |
373 | 370 | import { NavLink } from "react-router-dom";
|
374 | 371 |
|
375 | 372 | function NavList() {
|
@@ -411,7 +408,7 @@ function NavList() {
|
411 | 408 | If you prefer the v5 API, you can create your own `<NavLink />` as a wrapper component:
|
412 | 409 |
|
413 | 410 | ```tsx
|
414 |
| -import React from "react"; |
| 411 | +import * as React from "react"; |
415 | 412 | import { NavLink as BaseNavLink } from "react-router-dom";
|
416 | 413 |
|
417 | 414 | const NavLink = React.forwardRef(
|
@@ -472,7 +469,7 @@ A `<Navigate>` element changes the current location when it is rendered. It's a
|
472 | 469 | > subclass where hooks are not able to be used.
|
473 | 470 |
|
474 | 471 | ```tsx
|
475 |
| -import React from "react"; |
| 472 | +import * as React from "react"; |
476 | 473 | import { Navigate } from "react-router-dom";
|
477 | 474 |
|
478 | 475 | class LoginForm extends React.Component {
|
@@ -666,8 +663,8 @@ interface StaticRouterProps {
|
666 | 663 | - `<StaticRouter location>` defaults to `"/"`
|
667 | 664 |
|
668 | 665 | ```tsx
|
669 |
| -import React from "react"; |
670 |
| -import ReactDOMServer from "react-dom/server"; |
| 666 | +import * as React from "react"; |
| 667 | +import * as ReactDOMServer from "react-dom/server"; |
671 | 668 | import { StaticRouter } from "react-router-dom/server";
|
672 | 669 | import http from "http";
|
673 | 670 |
|
@@ -768,7 +765,7 @@ The term "location" in React Router refers to [the `Location` interface](https:/
|
768 | 765 |
|
769 | 766 | > **Note:**
|
770 | 767 | >
|
771 |
| -> The history package is React Router's main dependency and many of the |
| 768 | +> The `history` package is React Router's only dependency and many of the |
772 | 769 | > core types in React Router come directly from that library including
|
773 | 770 | > `Location`, `To`, `Path`, `State`, and others. You can read more about
|
774 | 771 | > the history library in [its documentation](https://github.com/remix-run/history/tree/main/docs).
|
@@ -1042,7 +1039,7 @@ interface Location<S extends State = object | null>
|
1042 | 1039 | This hook returns the current [`location`](#location) object. This can be useful if you'd like to perform some side effect whenever the current location changes.
|
1043 | 1040 |
|
1044 | 1041 | ```tsx
|
1045 |
| -import React from 'react'; |
| 1042 | +import * as React from 'react'; |
1046 | 1043 | import { useLocation } from 'react-router-dom';
|
1047 | 1044 |
|
1048 | 1045 | function App() {
|
@@ -1161,7 +1158,7 @@ declare function useParams<
|
1161 | 1158 | The `useParams` hook returns an object of key/value pairs of the dynamic params from the current URL that were matched by the `<Route path>`. Child routes inherit all params from their parent routes.
|
1162 | 1159 |
|
1163 | 1160 | ```tsx
|
1164 |
| -import React from 'react'; |
| 1161 | +import * as React from 'react'; |
1165 | 1162 | import { Routes, Route, useParams } from 'react-router-dom';
|
1166 | 1163 |
|
1167 | 1164 | function ProfilePage() {
|
@@ -1218,7 +1215,7 @@ The `useRoutes` hook is the functional equivalent of [`<Routes>`](#routes), but
|
1218 | 1215 | The return value of `useRoutes` is either a valid React element you can use to render the route tree, or `null` if nothing matched.
|
1219 | 1216 |
|
1220 | 1217 | ```tsx
|
1221 |
| -import React from "react"; |
| 1218 | +import * as React from "react"; |
1222 | 1219 | import { useRoutes } from "react-router-dom";
|
1223 | 1220 |
|
1224 | 1221 | function App() {
|
@@ -1279,7 +1276,7 @@ interface URLSearchParamsSetter {
|
1279 | 1276 | The `useSearchParams` hook is used to read and modify the query string in the URL for the current location. Like React's own [`useState` hook](https://reactjs.org/docs/hooks-reference.html#usestate), `useSearchParams` returns an array of two values: the current location's [search params](https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams) and a function that may be used to update them.
|
1280 | 1277 |
|
1281 | 1278 | ```tsx
|
1282 |
| -import React from "react"; |
| 1279 | +import * as React from "react"; |
1283 | 1280 | import { useSearchParams } from "react-router-dom";
|
1284 | 1281 |
|
1285 | 1282 | function App() {
|
@@ -1345,7 +1342,7 @@ interface URLSearchParamsSetter {
|
1345 | 1342 | The `useSearchParams` hook is used to read and modify the query string in the URL for the current location. Like React's own [`useState` hook](https://reactjs.org/docs/hooks-reference.html#usestate), `useSearchParams` returns an array of two values: the current location's [search params](https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams) and a function that may be used to update them.
|
1346 | 1343 |
|
1347 | 1344 | ```tsx
|
1348 |
| -import React from "react"; |
| 1345 | +import * as React from "react"; |
1349 | 1346 | import { View, SearchForm, TextInput } from "react-native";
|
1350 | 1347 | import { useSearchParams } from "react-router-native";
|
1351 | 1348 |
|
|
0 commit comments