Skip to content

Commit 075a2e0

Browse files
committed
Merge branch 'main' into release-next
2 parents e29876c + 43cc1aa commit 075a2e0

File tree

14 files changed

+308
-25
lines changed

14 files changed

+308
-25
lines changed

.github/workflows/support.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ jobs:
1616
issue-comment: >
1717
:wave: @{issue-author}, we use the issue tracker exclusively for bug reports
1818
and feature requests. However, this issue appears to be a support request.
19+
1920
For usage questions, please use [Stack Overflow](https://stackoverflow.com/questions/tagged/react-router)
20-
or [Reactiflux](https://discord.gg/6RyV8n8yyM) where there are a lot more people ready to help you out.
21+
or [Discord](https://rmx.as/discord) where there are a lot more people ready to help you out, or
22+
[post a new question](https://github.com/remix-run/react-router/discussions/new?category=q-a) in the
23+
Discussions tab of this repository.
2124
2225
Please feel free to clarify your issue if you think it was closed prematurely.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
React Router is a lightweight, fully-featured routing library for the [React](https://reactjs.org) JavaScript library. React Router runs everywhere that React runs; on the web, on the server (using node.js), and on React Native.
99

10-
If you're new to React Router, we recommend you start with [the tutorial](/docs/start/tutorial.md).
10+
If you're new to React Router, we recommend you start with [the tutorial](https://reactrouter.com/en/main/start/tutorial).
1111

1212
If you're migrating to v6 from v5 (or v4, which is the same as v5), check out [the migration guide](/docs/upgrading/v5.md). If you're migrating from Reach Router, check out [the migration guide for Reach Router](/docs/upgrading/reach.md). If you need to find the code for v5, [it is on the `v5` branch](https://github.com/remix-run/react-router/tree/v5).
1313

14-
When v6 is stable we will publish the docs on our website.
14+
Documentation for v6 can be found [on our website](https://reactrouter.com/).
1515

1616
## Contributing
1717

contributors.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- awreese
1717
- aymanemadidi
1818
- bavardage
19+
- bbrowning918
1920
- BDomzalski
2021
- bhbs
2122
- bobziroll
@@ -26,6 +27,7 @@
2627
- btav
2728
- bvangraafeiland
2829
- CanRau
30+
- cassidoo
2931
- chaance
3032
- chasinhues
3133
- chensokheng
@@ -52,6 +54,7 @@
5254
- engpetermwangi
5355
- FilipJirsak
5456
- frontsideair
57+
- fyzhu
5558
- fz6m
5659
- gianlucca
5760
- gijo-varghese
@@ -77,6 +80,7 @@
7780
- JakubDrozd
7881
- janpaepke
7982
- jasonpaulos
83+
- jdufresne
8084
- jenseng
8185
- JesusTheHun
8286
- jimniels
@@ -100,10 +104,12 @@
100104
- lkwr
101105
- lopezac
102106
- lordofthecactus
107+
- LordThi
103108
- loun4
104109
- lqze
105110
- lukerSpringTree
106111
- m-shojaei
112+
- machour
107113
- Manc
108114
- manzano78
109115
- marc2332

decisions/0001-use-blocker.md

Lines changed: 192 additions & 0 deletions
Large diffs are not rendered by default.

decisions/template.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Title
2+
3+
Date: YYYY-MM-DD
4+
5+
Status: proposed | rejected | accepted | deprecated | … | superseded by [0005](0005-example.md)
6+
7+
## Context
8+
9+
## Decision
10+
11+
## Consequences

docs/components/form.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ The method will be available on [`request.method`][requestmethod] inside the rou
132132
}}
133133
action={async ({ request, params }) => {
134134
switch (request.method) {
135-
case "put": {
135+
case "PUT": {
136136
let formData = await request.formData();
137137
let name = formData.get("projectName");
138138
return fakeUpdateProject(name);
139139
}
140-
case "delete": {
140+
case "DELETE": {
141141
return fakeDeleteProject(params.id);
142142
}
143143
default: {

docs/components/link.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ interface LinkProps
2121
state?: any;
2222
to: To;
2323
reloadDocument?: boolean;
24+
preventScrollReset?: boolean;
25+
relative?: "route" | "path";
2426
}
2527

2628
type To = string | Partial<Path>;
@@ -116,5 +118,26 @@ An example when you might want this behavior is a list of tabs that manipulate t
116118
117119
```
118120

121+
## `replace`
122+
123+
The `replace` property can be used if you'd like to replace the current entry in the history stack via [`history.replaceState`][history-replace-state] instead of the default usage of [`history.pushState`][history-push-state].
124+
125+
## `state`
126+
127+
The `state` property can be used to set a stateful value for the new location which is stored inside [history state][history-state]. This value can subsequently be accessed via `useLocation()`.
128+
129+
```tsx
130+
<Link to="new-path" state={{ some: "value" }} />
131+
```
132+
133+
You can access this state value while on the "new-path" route:
134+
135+
```ts
136+
let { state } = useLocation();
137+
```
138+
119139
[link-native]: ./link-native
120140
[scrollrestoration]: ./scroll-restoration
141+
[history-replace-state]: https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState
142+
[history-push-state]: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
143+
[history-state]: https://developer.mozilla.org/en-US/docs/Web/API/History/state

docs/route/route.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,39 @@ function Product() {
136136
}
137137
```
138138

139+
### Optional Segments
140+
141+
You can make a route segment optional by adding a `?` to the end of the segment.
142+
143+
```tsx
144+
<Route
145+
// this path will match URLs like
146+
// - /categories
147+
// - /en/categories
148+
// - /fr/categories
149+
path="/:lang?/categories"
150+
// the matching param might be available to the loader
151+
loader={({ params }) => {
152+
console.log(params["*"]); // "one/two"
153+
}}
154+
// and the action
155+
action={({ params }) => {}}
156+
element={<Categories />}
157+
/>;
158+
159+
// and the element through `useParams`
160+
function Categories() {
161+
let params = useParams();
162+
console.log(params.lang);
163+
}
164+
```
165+
166+
You can have optional static segments, too:
167+
168+
```jsx
169+
<Route path="/project/task?/:taskId" />
170+
```
171+
139172
### Splats
140173

141174
Also known as "catchall" and "star" segments. If a route path pattern ends with `/*` then it will match any characters following the `/`, including other `/` characters.

docs/router-components/browser-router.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ A `<BrowserRouter>` stores the current location in the browser's address bar usi
2727

2828
```tsx
2929
import * as React from "react";
30-
import * as ReactDOM from "react-dom";
30+
import { createRoot } from "react-dom/client";
3131
import { BrowserRouter } from "react-router-dom";
3232

33-
ReactDOM.render(
33+
const root = createRoot(document.getElementById("root"));
34+
35+
root.render(
3436
<BrowserRouter>
3537
{/* The rest of your app goes here */}
36-
</BrowserRouter>,
37-
root
38+
</BrowserRouter>
3839
);
3940
```
4041

docs/start/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ export default function Root() {
139139
<nav>
140140
<ul>
141141
<li>
142-
<a href={`contacts/1`}>Your Name</a>
142+
<a href={`/contacts/1`}>Your Name</a>
143143
</li>
144144
<li>
145-
<a href={`contacts/2`}>Your Friend</a>
145+
<a href={`/contacts/2`}>Your Friend</a>
146146
</li>
147147
</ul>
148148
</nav>

docs/upgrading/v5.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,30 @@ function App() {
560560
}
561561
```
562562

563+
## Pass `<Link>` state as separate prop
564+
565+
The `Link` component in v6 accepts `state` as a separate prop instead of receiving it as part of the object passed to `to` so you'll need to update your `Link` components if they are using `state`:
566+
567+
```js
568+
import { Link } from "react-router-dom";
569+
570+
// Change this:
571+
<Link to={{ pathname: "/home", state: state }} />
572+
573+
// to this:
574+
<Link to="/home" state={state} />
575+
```
576+
577+
The state value is still retrieved in the linked component using `useLocation()`:
578+
579+
```js
580+
function Home() {
581+
const location = useLocation();
582+
const state = location.state;
583+
return <div>Home</div>;
584+
}
585+
```
586+
563587
## Use `useRoutes` instead of `react-router-config`
564588

565589
All of the functionality from v5's `react-router-config` package has moved into core in v6. If you prefer/need to define your routes as JavaScript objects instead of using React elements, you're going to love this.
@@ -636,17 +660,7 @@ function App() {
636660
}
637661
```
638662

639-
If you need to replace the current location instead of push a new one onto the history stack, use `navigate(to, { replace: true })`. If you need state, use `navigate(to, { state })`. You can think of the first argument to `navigate` as your `<Link to>` and the other arguments as the `replace` and `state` props. The `Link` component in v6 accepts `state` as a separate prop instead of receiving it as part of the object passed to `to` so you'll need to update your `Link` components if they are using `state`:
640-
641-
```js
642-
import { Link } from "react-router-dom";
643-
644-
// Change this:
645-
<Link to={{ pathname: "/home", state: state }} />
646-
647-
// to this:
648-
<Link to="/home" state={state} />
649-
```
663+
If you need to replace the current location instead of push a new one onto the history stack, use `navigate(to, { replace: true })`. If you need state, use `navigate(to, { state })`. You can think of the first argument to `navigate` as your `<Link to>` and the other arguments as the `replace` and `state` props.
650664

651665
If you prefer to use a declarative API for navigation (ala v5's `Redirect` component), v6 provides a `Navigate` component. Use it like:
652666

packages/react-router-dom/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
The `react-router-dom` package contains bindings for using [React
44
Router](https://github.com/remix-run/react-router) in web applications.
5-
Please see [the Getting Started guide](https://github.com/remix-run/react-router/blob/main/docs/start/tutorial.md) for more information on how to get started with React Router.
5+
Please see [the Getting Started guide](https://reactrouter.com/en/main/start/tutorial) for more information on how to get started with React Router.

packages/react-router-native/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
The `react-router-native` package contains bindings for using [React
44
Router](https://github.com/remix-run/react-router) in [React
55
Native](https://facebook.github.io/react-native/) applications.
6-
Please see [the Getting Started guide](https://github.com/remix-run/react-router/blob/main/docs/start/tutorial.md) for more information on how to get started with React Router.
6+
Please see [the Getting Started guide](https://reactrouter.com/en/main/start/tutorial) for more information on how to get started with React Router.

tutorial/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# React Router v6 Tutorial
22

3-
To complete this tutorial, we recommend following along with our guide in our [Getting Started documentation](https://github.com/remix-run/react-router/blob/main/docs/start/tutorial.md).
3+
To complete this tutorial, we recommend following along with our guide in our [Getting Started documentation](https://reactrouter.com/en/main/start/tutorial).

0 commit comments

Comments
 (0)