You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DEVELOPMENT.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,15 +41,19 @@ You may need to make changes to a pre-release prior to publishing a final stable
41
41
- Commit the edited pre-release file along with any unpublished changesets, and push the `release-*` branch to GitHub.
42
42
- Wait for the release workflow to finish. The Changesets action in the workflow will open a PR that will increment all versions and generate the changelogs for the stable release.
43
43
- Review the updated `CHANGELOG` files and make any adjustments necessary.
Copy file name to clipboardExpand all lines: docs/components/link.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ A relative `<Link to>` value (that does not begin with `/`) resolves relative to
64
64
65
65
## `relative`
66
66
67
-
By default, links are relative to the route hierarchy, so `..` will go up one `Route` level. Occasionally, you may find that you have matching URL patterns that do not make sense to be nested, and you'd prefer to use relative _path_ routing. You can opt into this behavior with `relative`:
67
+
By default, links are relative to the route hierarchy (`relative="route"`), so `..` will go up one `Route` level. Occasionally, you may find that you have matching URL patterns that do not make sense to be nested, and you'd prefer to use relative _path_ routing. You can opt into this behavior with `relative="path"`:
68
68
69
69
```jsx
70
70
// Contact and EditContact do not share additional UI layout
Copy file name to clipboardExpand all lines: docs/components/nav-link.md
+4-16Lines changed: 4 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,29 +84,17 @@ You can pass a render prop as children to customize the content of the `<NavLink
84
84
85
85
The `end` prop changes the matching logic for the `active` and `pending` states to only match to the "end" of the NavLink's `to` path. If the URL is longer than `to`, it will no longer be considered active.
86
86
87
-
Without the end prop, this link is always active because every URL matches `/`.
88
-
89
-
```tsx
90
-
<NavLinkto="/">Home</NavLink>
91
-
```
92
-
93
-
To match the URL "to the end" of `to`, use `end`:
94
-
95
-
```tsx
96
-
<NavLinkto="/"end>
97
-
Home
98
-
</NavLink>
99
-
```
100
-
101
-
Now this link will only be active at `"/"`. This works for paths with more segments as well:
|`<NavLink to="/tasks" end />`|`/tasks/123`| false |
109
93
94
+
**A note on links to the root route**
95
+
96
+
`<NavLink to="/">` is an exceptional case because _every_ URL matches `/`. To avoid this matching every single route by default, it effectively ignores the `end` prop and only matches when you're at the root route.
97
+
110
98
## `caseSensitive`
111
99
112
100
Adding the `caseSensitive` prop changes the matching logic to make it case sensitive.
Copy file name to clipboardExpand all lines: docs/hooks/use-navigate.md
+58-19Lines changed: 58 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,29 @@ title: useNavigate
4
4
5
5
# `useNavigate`
6
6
7
+
<details>
8
+
<summary>Type declaration</summary>
9
+
10
+
```tsx
11
+
declarefunction useNavigate():NavigateFunction;
12
+
13
+
interfaceNavigateFunction {
14
+
(to:To, options?:NavigateOptions):void;
15
+
(delta:number):void;
16
+
}
17
+
18
+
interfaceNavigateOptions {
19
+
replace?:boolean;
20
+
state?:any;
21
+
preventScrollReset?:boolean;
22
+
relative?:RelativeRoutingType;
23
+
}
24
+
25
+
typeRelativeRoutingType="route"|"path";
26
+
```
27
+
28
+
</details>
29
+
7
30
<docs-warning>It's usually better to use [`redirect`][redirect] in [`loaders`][loaders] and [`actions`][actions] than this hook</docs-warning>
8
31
9
32
The `useNavigate` hook returns a function that lets you navigate programmatically, for example in an effect:
@@ -24,31 +47,47 @@ function useLogoutTimer() {
24
47
}
25
48
```
26
49
27
-
## Type Declaration
50
+
The `navigate` function has two signatures:
28
51
29
-
```tsx
30
-
declarefunction useNavigate():NavigateFunction;
52
+
- Either pass a `To` value (same type as `<Link to>`) with an optional second `options` argument (similar to the props you can pass to [`<Link>`][link]), or
53
+
- Pass the delta you want to go in the history stack. For example, `navigate(-1)` is equivalent to hitting the back button
31
54
32
-
interfaceNavigateFunction {
33
-
(
34
-
to:To,
35
-
options?: {
36
-
replace?:boolean;
37
-
state?:any;
38
-
relative?:RelativeRoutingType;
39
-
}
40
-
):void;
41
-
(delta:number):void;
42
-
}
43
-
```
55
+
## `options.replace`
44
56
45
-
The `navigate` function has two signatures:
57
+
Specifying `replace: true` will cause the navigation will replace the current entry in the history stack instead of adding a new one.
58
+
59
+
## `options.state`
46
60
47
-
- Either pass a `To` value (same type as `<Link to>`) with an optional second `{ replace, state }` arg or
48
-
- Pass the delta you want to go in the history stack. For example, `navigate(-1)` is equivalent to hitting the back button.
61
+
You may include an optional state value in to store in [history state][history-state]
49
62
50
-
If using `replace: true`, the navigation will replace the current entry in the history stack instead of adding a new one.
63
+
## `options.preventScrollReset`
64
+
65
+
When using the [`<ScrollRestoration>`][scrollrestoration] component, you can disable resetting the scroll to the top of the page via `options.preventScrollReset`
66
+
67
+
## `options.relative`
68
+
69
+
By default, navigation is relative to the route hierarchy (`relative: "route"`), so `..` will go up one `Route` level. Occasionally, you may find that you have matching URL patterns that do not make sense to be nested, and you'd prefer to use relative _path_ routing. You can opt into this behavior with `relative: "path"`:
70
+
71
+
```jsx
72
+
// Contact and EditContact do not share additional UI layout
Copy file name to clipboardExpand all lines: docs/hooks/use-outlet-context.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ function Child() {
36
36
37
37
If you're using TypeScript, we recommend the parent component provide a custom hook for accessing the context value. This makes it easier for consumers to get nice typings, control consumers, and know who's consuming the context value. Here's a more realistic example:
Copy file name to clipboardExpand all lines: docs/hooks/use-submit.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -153,4 +153,4 @@ submit(null, {
153
153
Because submissions are navigations, the options may also contain the other navigation related props from [`<Form>`][form] such as `replace`, `state`, `preventScrollReset`, `relative`, etc.
Copy file name to clipboardExpand all lines: docs/routers/create-browser-router.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,8 @@ This is the recommended router for all React Router web projects. It uses the [D
9
9
10
10
It also enables the v6.4 data APIs like [loaders][loader], [actions][action], [fetchers][fetcher] and more.
11
11
12
+
<docs-info>Due to the decoupling of fetching and rendering in the design of the data APIs, you should create your router outside of the React tree with a statically defined set of routes. For more information on this design, please see the [Remixing React Router][remixing-react-router] blog post and the [When to Fetch][when-to-fetch] conference talk.</docs-info>
13
+
12
14
```tsx lines=[4,11-24]
13
15
import*asReactfrom"react";
14
16
import*asReactDOMfrom"react-dom";
@@ -125,3 +127,5 @@ Useful for environments like browser devtool plugins or testing to use a differe
Copy file name to clipboardExpand all lines: docs/routers/router-provider.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,8 @@ interface RouterProviderProps {
24
24
25
25
All [data router][picking-a-router] objects are passed to this component to render your app and enable the rest of the data APIs.
26
26
27
+
<docs-info>Due to the decoupling of fetching and rendering in the design of the data APIs, you should create your router outside of the React tree with a statically defined set of routes. For more information on this design, please see the [Remixing React Router][remixing-react-router] blog post and the [When to Fetch][when-to-fetch] conference talk.</docs-info>
0 commit comments