Skip to content

Commit 0546ba9

Browse files
authored
6.4 Docs Updates (#9151)
* docs: minor typing updates to align with docs * Add new indicator to fetch utils * Various other typo fixes and link fixes * fix up types for scroll restoration matches * Revert "docs: minor typing updates to align with docs" This reverts commit e1b52ed. * Revert "fix up types for scroll restoration matches" This reverts commit e714bd2. * Remove duped link * Remix -> React Router * Add docs for new 'relative=path' option
1 parent 29a3bca commit 0546ba9

18 files changed

+88
-24
lines changed

docs/components/form.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ We've found with `get` you often want the user to be able to click "back" to see
187187

188188
In other words, this is really only useful for GET submissions and you want to avoid the back button showing the previous results.
189189

190+
## `relative`
191+
192+
By default, paths 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're prefer to use relative _path_ routing. You can opt into this behavior with `<Form to="../some/where" relative="path">`
193+
190194
## `reloadDocument`
191195

192196
Instructs the form to skip React Router and submit the form with the browser's built in behavior.

docs/components/link.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Link
44

55
# `<Link>`
66

7-
<docs-info>ZZZ This is the web version of `<Link>`. For the React Native version, [go here][link-native].</docs-info>
7+
<docs-info>This is the web version of `<Link>`. For the React Native version, [go here][link-native].</docs-info>
88

99
<details>
1010
<summary>Type declaration</summary>
@@ -54,7 +54,30 @@ A relative `<Link to>` value (that does not begin with `/`) resolves relative to
5454

5555
<docs-info>`<Link to>` with a `..` behaves differently from a normal `<a href>` when the current URL ends with `/`. `<Link to>` ignores the trailing slash, and removes one URL segment for each `..`. But an `<a href>` value handles `..` differently when the current URL ends with `/` vs when it does not.</docs-info>
5656

57-
[link-native]: ./link-native
57+
## `relative`
58+
59+
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're prefer to use relative _path_ routing. You can opt into this behavior with `relative`:
60+
61+
```jsx
62+
// Contact and EditContact do not share additional UI layout
63+
<Route path="/" element={<Layout />}>
64+
<Route path="contacts/:id" element={<Contact />} />
65+
<Route
66+
path="contacts/:id/edit"
67+
element={<EditContact />}
68+
/>
69+
</Route>;
70+
71+
function EditContact() {
72+
// Since Contact is not a parent of EditContact we need to go up one level
73+
// in the path, instead of one level in the Route hierarchy
74+
return (
75+
<Link to=".." relative="path">
76+
Cancel
77+
</Link>
78+
);
79+
}
80+
```
5881

5982
## `preventScrollReset`
6083

@@ -93,4 +116,5 @@ An example when you might want this behavior is a list of tabs that manipulate t
93116
94117
```
95118

119+
[link-native]: ./link-native
96120
[scrollrestoration]: ./scroll-restoration

docs/components/navigate.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface NavigateProps {
1414
to: To;
1515
replace?: boolean;
1616
state?: any;
17+
relative?: RelativeRoutingType;
1718
}
1819
```
1920

docs/getting-started/_data.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ React Router v6.4 introduces all of the data abstractions from [Remix][remix] fo
1515

1616
## Installation
1717

18-
The new Data APIs are available on the `next` tag:
18+
The new Data APIs are available on the `pre` tag:
1919

2020
```sh
21-
npm install react-router-dom@next
21+
npm install react-router-dom@pre
2222
```
2323

2424
## Configuring Routes
2525

26-
Configuring routes is the same, except you need to use [`DataBrowserRouter`][databrowserrouter] to enable the data APIs. note you no longer render `<Routes>` either, just `<Route>`.
26+
Configuring routes is the same, except you need to use [`DataBrowserRouter`][databrowserrouter] to enable the data APIs. Note you no longer render `<Routes>` either, just `<Route>`.
2727

2828
<docs-info>It's important to render `DataBrowserRouter` at the top of the React tree.</docs-info>
2929

@@ -255,6 +255,7 @@ export default function Root() {
255255
With the route configured, we can create an [`action`][action]. Actions are like [loaders][loader] except instead "reading" data they "write" data. Think of it like `React.useState`. It returns a reader and a writer. In React Router, loaders are your readers, actions are your writers.
256256
257257
```jsx
258+
// Sample code - this does not actually work :)
258259
const [reader, writer] = React.useState();
259260
<Route loader={reader} action={writer} />;
260261
```
@@ -283,7 +284,7 @@ export default function NewNote() {
283284
284285
Now add it to the route config:
285286
286-
```jsx filename=main.jsx lines=[3,13]
287+
```jsx filename=main.jsx lines=[4,13]
287288
// ...
288289
import Root, { loader as rootLoader } from "./routes/root";
289290
import NewNote, {

docs/hooks/use-async-error.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Returns the rejection value from the nearest [`<Await>`][await] component.
1010
```tsx [4,12]
1111
import { useAsyncError, Await } from "react-router-dom";
1212

13-
function ErrorHandler() {
13+
function ErrorElement() {
1414
const error = useAsyncError();
1515
return (
1616
<p>Uh Oh, something went wrong! {error.message}</p>

docs/hooks/use-fetcher.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ You can know the state of the fetcher with `fetcher.state`. It will be one of:
6262

6363
- **idle** - nothing is being fetched.
6464
- **submitting** - A route action is being called due to a fetcher submission using POST, PUT, PATCH, or DELETE
65-
- **loading** - The fetcher is calling a loader (from a `fetcher.load`) or the route data on the page is being revalidated after a fetcher submission
65+
- **loading** - The fetcher is calling a loader (from a `fetcher.load`) or is being revalidated after a separate submission or `useRevalidator` call
6666

6767
## `fetcher.Form`
6868

@@ -220,6 +220,6 @@ Tells you the method of the form being submitted: get, post, put, patch, or dele
220220
fetcher.formMethod; // "post"
221221
```
222222

223-
[indexsearchparam]: ../route/route
223+
[indexsearchparam]: ../guides/index-search-param
224224
[link]: ../components/link
225225
[form]: ../components/form

docs/hooks/use-form-action.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@ new: true
55

66
# `useFormAction`
77

8-
This hook is used internally in [Form] to automatically resolve default and relative actions to the current route in context. While uncommon, you can use it directly to do things like compute the correct action for a `<button formAction>` to change the action of the button's `<Form>`. <small>(Yes, HTML buttons can change the action of their form!)</small>
8+
<details>
9+
<summary>Type declaration</summary>
10+
11+
```tsx
12+
declare function useFormAction(
13+
action?: string,
14+
{ relative }: { relative?: RelativeRoutingType } = {}
15+
): string;
16+
```
17+
18+
</details>
19+
20+
This hook is used internally in [`<Form>`][form] to automatically resolve default and relative actions to the current route in context. While uncommon, you can use it directly to do things like compute the correct action for a `<button formAction>` to change the action of the button's `<Form>`. <small>(Yes, HTML buttons can change the action of their form!)</small>
921

1022
```tsx
1123
import { useFormAction } from "react-router-dom";
@@ -26,9 +38,10 @@ It's also useful for automatically resolving the action for [`submit`][usesubmit
2638

2739
```tsx
2840
let submit = useSubmit();
29-
let action = useResolvedAction();
41+
let action = useFormAction();
3042
submit(formData, { action });
3143
```
3244

45+
[form]: ../components/form
3346
[usesubmit]: ./use-submit
3447
[usefetchersubmit]: ./use-fetcher#fetchersubmit

docs/hooks/use-href.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ title: useHref
88
<summary>Type declaration</summary>
99

1010
```tsx
11-
declare function useHref(to: To): string;
11+
declare function useHref(
12+
to: To,
13+
options?: { relative?: RelativeRoutingType }
14+
): string;
1215
```
1316

1417
</details>

docs/hooks/use-link-click-handler.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ declare function useLinkClickHandler<
1616
target?: React.HTMLAttributeAnchorTarget;
1717
replace?: boolean;
1818
state?: any;
19+
options?: { relative?: RelativeRoutingType };
1920
}
2021
): (event: React.MouseEvent<E, MouseEvent>) => void;
2122
```

docs/hooks/use-navigate.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ declare function useNavigate(): NavigateFunction;
3131
interface NavigateFunction {
3232
(
3333
to: To,
34-
options?: { replace?: boolean; state?: any }
34+
options?: {
35+
replace?: boolean;
36+
state?: any;
37+
relative?: RelativeRoutingType;
38+
}
3539
): void;
3640
(delta: number): void;
3741
}

0 commit comments

Comments
 (0)