@modern-js/main-doc 0.0.0-next-20221227140603 → 0.0.0-next-20221228051706
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +2 -27
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/router/router.md +176 -373
- package/en/docusaurus-plugin-content-docs/current/components/enable-bff.md +36 -0
- package/en/docusaurus-plugin-content-docs/current/components/router-legacy-tip.md +1 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/runtime/router.md +17 -2
- package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/bff/frameworks.md +2 -0
- package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/bff/function.md +10 -6
- package/en/docusaurus-plugin-content-docs/current/guides/basic-features/data-fetch.md +1 -0
- package/en/docusaurus-plugin-content-docs/current/guides/basic-features/routes.md +0 -2
- package/package.json +3 -3
- package/zh/apis/app/runtime/router/router.md +170 -368
- package/zh/components/enable-bff.md +36 -0
- package/zh/components/micro-master-manifest-config.md +15 -0
- package/zh/components/router-legacy-tip.md +1 -0
- package/zh/configure/app/runtime/master-app.md +2 -16
- package/zh/configure/app/runtime/router.md +17 -3
- package/zh/guides/advanced-features/bff/frameworks.md +2 -0
- package/zh/guides/advanced-features/bff/function.md +7 -5
- package/zh/guides/basic-features/data-fetch.md +1 -0
- package/zh/guides/basic-features/routes.md +0 -3
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/with-master-app.md +0 -31
- package/zh/configure/app/dev/with-master-app.md +0 -32
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
@@ -1,33 +1,8 @@
|
|
1
1
|
# @modern-js/main-doc
|
2
2
|
|
3
|
-
## 0.0.0-next-
|
3
|
+
## 0.0.0-next-20221228051706
|
4
4
|
|
5
5
|
### Patch Changes
|
6
6
|
|
7
|
-
- 7879e8f71: refactor: remove enableModernMode config
|
8
|
-
|
9
|
-
refactor: 不再支持 enableModernMode 配置项
|
10
|
-
|
11
|
-
- 5927355ee: feat: develop documentation directly with main-doc
|
12
|
-
feat: 直接使用 main-doc 包开发文档
|
13
|
-
- ebf899fb5: feat(app-tools): support configure builder plugins
|
14
|
-
|
15
|
-
feat(app-tools): 支持配置 builder 插件
|
16
|
-
|
17
|
-
- 1ef69374b: feat: support update main-doc when package build or website build
|
18
|
-
feat: 支持在包发布和官网发布时,更新 main-doc 包
|
19
|
-
- Updated dependencies [2bc090c08]
|
20
|
-
- Updated dependencies [f96a72521]
|
21
|
-
- Updated dependencies [57077b2c6]
|
22
|
-
- Updated dependencies [2ff6167be]
|
23
|
-
- Updated dependencies [309f08bdf]
|
24
|
-
- Updated dependencies [5402fdb0c]
|
25
|
-
- Updated dependencies [10d08a480]
|
26
|
-
- Updated dependencies [5d67c26cd]
|
27
|
-
- Updated dependencies [af4422d67]
|
28
7
|
- Updated dependencies [dda38c9c3]
|
29
|
-
-
|
30
|
-
- Updated dependencies [3fae2d03b]
|
31
|
-
- Updated dependencies [df41d71ad]
|
32
|
-
- Updated dependencies [14b712da8]
|
33
|
-
- @modern-js/builder-doc@0.0.0-next-20221227140603
|
8
|
+
- @modern-js/builder-doc@0.0.0-next-20221228051706
|
@@ -3,32 +3,44 @@ title: router
|
|
3
3
|
sidebar_position: 1
|
4
4
|
---
|
5
5
|
|
6
|
-
:::info
|
7
|
-
|
6
|
+
:::info
|
7
|
+
The router solution based on [react-router 6](https://reactrouter.com/).
|
8
8
|
:::
|
9
9
|
|
10
|
-
:::caution
|
11
|
-
|
10
|
+
:::caution
|
11
|
+
Make sure the [router plugin](/docs/configure/app/runtime/router) is opted in before using the API.
|
12
12
|
:::
|
13
13
|
|
14
14
|
## hooks
|
15
15
|
|
16
|
-
###
|
16
|
+
### useNavigate
|
17
17
|
|
18
18
|
```ts
|
19
|
-
function
|
19
|
+
declare function useNavigate(): NavigateFunction;
|
20
|
+
|
21
|
+
interface NavigateFunction {
|
22
|
+
(
|
23
|
+
to: To,
|
24
|
+
options?: {
|
25
|
+
replace?: boolean;
|
26
|
+
state?: any;
|
27
|
+
relative?: RelativeRoutingType;
|
28
|
+
}
|
29
|
+
): void;
|
30
|
+
(delta: number): void;
|
31
|
+
}
|
20
32
|
```
|
21
33
|
|
22
|
-
|
34
|
+
The `useNavigate` hook returns a function that lets you navigate programmatically。
|
23
35
|
|
24
36
|
```tsx
|
25
|
-
import {
|
37
|
+
import { useNavigate } from "@modern-js/runtime/router";
|
26
38
|
|
27
39
|
export function HomeButton() {
|
28
|
-
let
|
40
|
+
let navigate = useNavigate();
|
29
41
|
|
30
42
|
function handleClick() {
|
31
|
-
|
43
|
+
navigate("/home");
|
32
44
|
}
|
33
45
|
|
34
46
|
return (
|
@@ -42,20 +54,18 @@ export function HomeButton() {
|
|
42
54
|
### useLocation
|
43
55
|
|
44
56
|
```ts
|
45
|
-
function useLocation
|
57
|
+
declare function useLocation(): Location;
|
58
|
+
|
59
|
+
interface Location extends Path {
|
60
|
+
state: unknown;
|
61
|
+
key: Key;
|
62
|
+
}
|
46
63
|
```
|
47
64
|
|
48
|
-
`useLocation`
|
65
|
+
The `useLocation` hook returns the current [location](https://reactrouter.com/web/api/location) object. A new location object would be returned whenever the current location changes.
|
49
66
|
|
50
67
|
```ts
|
51
|
-
import
|
52
|
-
import { bootstrap, createApp } from '@modern-js/runtime';
|
53
|
-
import { router } from '@modern-js/runtime/plugins';
|
54
|
-
import {
|
55
|
-
BrowserRouter as Router,
|
56
|
-
Switch,
|
57
|
-
useLocation
|
58
|
-
} from "@modern-js/runtime/router";
|
68
|
+
import { useLocation } from "@modern-js/runtime/router";
|
59
69
|
|
60
70
|
function usePageViews() {
|
61
71
|
let location = useLocation();
|
@@ -66,26 +76,25 @@ function usePageViews() {
|
|
66
76
|
|
67
77
|
function App() {
|
68
78
|
usePageViews();
|
69
|
-
return
|
79
|
+
return (
|
80
|
+
//...
|
81
|
+
);
|
70
82
|
}
|
71
83
|
```
|
72
84
|
|
73
85
|
### useParams
|
74
86
|
|
75
87
|
```ts
|
76
|
-
function useParams<
|
77
|
-
|
78
|
-
|
79
|
-
} = {}
|
80
|
-
>(): Params;
|
88
|
+
declare function useParams<
|
89
|
+
K extends string = string
|
90
|
+
>(): Readonly<Params<K>>;
|
81
91
|
```
|
82
92
|
|
83
|
-
`useParams`
|
93
|
+
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>`.
|
84
94
|
|
85
95
|
```tsx
|
86
|
-
import React from "react";
|
87
96
|
import {
|
88
|
-
|
97
|
+
Routes,
|
89
98
|
Route,
|
90
99
|
useParams
|
91
100
|
} from "@modern-js/runtime/router";
|
@@ -96,397 +105,191 @@ function BlogPost() {
|
|
96
105
|
}
|
97
106
|
|
98
107
|
function App() {
|
99
|
-
return
|
100
|
-
<
|
101
|
-
<div>home</div>
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
</Route>
|
106
|
-
</Switch>
|
108
|
+
return (
|
109
|
+
<Routes>
|
110
|
+
<Route path="/" element={ <div>home</div> } />
|
111
|
+
<Route path="/blog/:slug" element={ <BlogPost />}/>
|
112
|
+
</Routes>
|
113
|
+
)
|
107
114
|
}
|
108
115
|
```
|
109
116
|
|
110
|
-
|
111
|
-
|
112
|
-
```ts
|
113
|
-
function useRouteMatch<
|
114
|
-
Params extends { [K in keyof Params]?: string } = {}
|
115
|
-
>(): match<Params>;
|
116
|
-
|
117
|
-
function useRouteMatch<
|
118
|
-
Params extends { [K in keyof Params]?: string } = {}
|
119
|
-
>(
|
120
|
-
path: string | string[] | RouteProps,
|
121
|
-
): match<Params> | null;
|
122
|
-
```
|
123
|
-
|
124
|
-
`useRouteMatch` 和 `<Route />` 一样是对路由进行匹配,但无须去渲染 `<Route />` 组件,便能获取到当前匹配结果。
|
125
|
-
|
126
|
-
## 组件
|
127
|
-
|
128
|
-
|
117
|
+
## Components
|
129
118
|
|
130
119
|
### Link
|
131
120
|
|
132
121
|
```ts
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
122
|
+
declare function Link(props: LinkProps): React.ReactElement;
|
123
|
+
|
124
|
+
interface LinkProps
|
125
|
+
extends Omit<
|
126
|
+
React.AnchorHTMLAttributes<HTMLAnchorElement>,
|
127
|
+
"href"
|
128
|
+
> {
|
129
|
+
replace?: boolean;
|
130
|
+
state?: any;
|
131
|
+
to: To;
|
132
|
+
reloadDocument?: boolean;
|
133
|
+
}
|
140
134
|
|
141
|
-
|
142
|
-
<Link to="/about">About</Link>
|
135
|
+
type To = string | Partial<Path>;
|
143
136
|
```
|
144
137
|
|
145
|
-
|
146
|
-
|
147
|
-
**to**
|
148
|
-
|
149
|
-
类型: `string | object | function`
|
150
|
-
|
151
|
-
`string`
|
138
|
+
A `<Link>` is an element that lets the user navigate to another page by clicking or tapping on it.
|
152
139
|
|
153
140
|
```ts
|
154
|
-
<Link to="/
|
155
|
-
```
|
156
|
-
|
157
|
-
`object`
|
158
|
-
|
159
|
-
```tsx
|
160
|
-
<Link
|
161
|
-
to={{
|
162
|
-
pathname: "/courses",
|
163
|
-
search: "?sort=name",
|
164
|
-
hash: "#the-hash",
|
165
|
-
state: { fromDashboard: true }
|
166
|
-
}}
|
167
|
-
/>
|
168
|
-
```
|
169
|
-
|
170
|
-
`function`
|
171
|
-
|
172
|
-
```tsx
|
173
|
-
<Link to={location => ({ ...location, pathname: "/courses" })} />
|
174
|
-
|
175
|
-
<Link to={location => `${location.pathname}?sort=name`} />
|
176
|
-
```
|
177
|
-
|
178
|
-
**replace**
|
179
|
-
|
180
|
-
类型: `boolean`
|
181
|
-
|
182
|
-
当设置为 `true` 时,在跳转的时候替换掉 history 栈中的栈顶路由,而不是添加一个新路由。
|
183
|
-
|
184
|
-
**component**
|
185
|
-
|
186
|
-
类型: `Component`
|
187
|
-
|
188
|
-
如果你想自定义你自己的路由跳转的组件,可以通过传入 `component` 来实现。
|
189
|
-
|
190
|
-
```tsx
|
191
|
-
simply do so by passing it through the component prop.const FancyLink = React.forwardRef((props, ref) => (
|
192
|
-
<a ref={ref} {...props}>💅 {props.children}</a>
|
193
|
-
))
|
194
|
-
|
195
|
-
<Link to="/" component={FancyLink} />
|
141
|
+
<Link to="/about">About</Link>
|
196
142
|
```
|
197
143
|
|
198
144
|
### NavLink
|
199
145
|
|
200
146
|
```ts
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
类型: `object`
|
227
|
-
|
228
|
-
设置路由匹配时额外的样式。
|
229
|
-
|
230
|
-
```tsx
|
231
|
-
<NavLink
|
232
|
-
to="/faq"
|
233
|
-
activeStyle={{
|
234
|
-
fontWeight: "bold",
|
235
|
-
color: "red"
|
236
|
-
}}
|
237
|
-
>
|
238
|
-
FAQs
|
239
|
-
</NavLink>
|
240
|
-
```
|
241
|
-
|
242
|
-
**exact**
|
243
|
-
|
244
|
-
类型: `boolean`
|
245
|
-
|
246
|
-
|
247
|
-
**strict**
|
248
|
-
|
249
|
-
类型: `boolean`
|
250
|
-
|
251
|
-
**isActive**
|
252
|
-
|
253
|
-
类型: `function`
|
254
|
-
|
255
|
-
如果你想自定义当前 Link 是否激活的逻辑,可以使用 `isActive`。
|
256
|
-
|
257
|
-
```tsx
|
258
|
-
<NavLink
|
259
|
-
to="/events/123"
|
260
|
-
isActive={(match, location) => {
|
261
|
-
if (!match) {
|
262
|
-
return false;
|
263
|
-
}
|
264
|
-
|
265
|
-
// only consider an event active if its event id is an odd number
|
266
|
-
const eventID = parseInt(match.params.eventID);
|
267
|
-
return !isNaN(eventID) && eventID % 2 === 1;
|
268
|
-
}}
|
269
|
-
>
|
270
|
-
Event 123
|
271
|
-
</NavLink>
|
272
|
-
```
|
273
|
-
|
274
|
-
**location**
|
275
|
-
|
276
|
-
类型: `object`
|
277
|
-
|
278
|
-
`NavLink` 默认会和当前的 `history.location` 进行匹配,判断是否处于激活状态。如果你想指定要匹配的 `location` 对象,可以使用该参数。
|
279
|
-
|
280
|
-
**area-current**
|
281
|
-
|
282
|
-
类型: `string`
|
283
|
-
|
284
|
-
参考 [aria-current](https://www.w3.org/TR/wai-aria-1.1/#aria-current)
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
### Prompt
|
289
|
-
|
290
|
-
```ts
|
291
|
-
interface PromptProps {
|
292
|
-
message: string | ((location: H.Location, action: H.Action) => string | boolean);
|
293
|
-
when?: boolean;
|
147
|
+
declare function NavLink(
|
148
|
+
props: NavLinkProps
|
149
|
+
): React.ReactElement;
|
150
|
+
|
151
|
+
interface NavLinkProps
|
152
|
+
extends Omit<
|
153
|
+
LinkProps,
|
154
|
+
"className" | "style" | "children"
|
155
|
+
> {
|
156
|
+
caseSensitive?: boolean;
|
157
|
+
children?:
|
158
|
+
| React.ReactNode
|
159
|
+
| ((props: { isActive: boolean }) => React.ReactNode);
|
160
|
+
className?:
|
161
|
+
| string
|
162
|
+
| ((props: {
|
163
|
+
isActive: boolean;
|
164
|
+
}) => string | undefined);
|
165
|
+
end?: boolean;
|
166
|
+
style?:
|
167
|
+
| React.CSSProperties
|
168
|
+
| ((props: {
|
169
|
+
isActive: boolean;
|
170
|
+
}) => React.CSSProperties);
|
294
171
|
}
|
295
|
-
|
296
|
-
class Prompt extends React.Component<PromptProps, any> {}
|
297
|
-
```
|
298
|
-
|
299
|
-
`Prompt` 组件可用于在页面跳转前,进行二次确认是否跳转。
|
300
|
-
|
301
|
-
```tsx
|
302
|
-
<Prompt
|
303
|
-
when={formIsHalfFilledOut}
|
304
|
-
message="Are you sure you want to leave?"
|
305
|
-
/>
|
306
172
|
```
|
307
173
|
|
308
|
-
|
309
|
-
|
310
|
-
**message**
|
311
|
-
|
312
|
-
类型: `string` | `function`
|
313
|
-
|
314
|
-
在页面跳转前的二次确认提示信息,支持传入函数形式。
|
315
|
-
|
316
|
-
```tsx
|
317
|
-
<Prompt
|
318
|
-
message={(location, action) => {
|
319
|
-
if (action === 'POP') {
|
320
|
-
console.log("Backing up...")
|
321
|
-
}
|
322
|
-
|
323
|
-
return location.pathname.startsWith("/app")
|
324
|
-
? true
|
325
|
-
: `Are you sure you want to go to ${location.pathname}?`
|
326
|
-
}}
|
327
|
-
/>
|
328
|
-
```
|
174
|
+
A `<NavLink>` is a special kind of `<Link>` that knows whether or not it is "active".
|
329
175
|
|
330
|
-
**when**
|
331
176
|
|
332
|
-
|
333
|
-
|
334
|
-
当 `when` 为 `true` 时,才会在页面跳转前展示二次确认提示。
|
335
|
-
|
336
|
-
|
337
|
-
### Route
|
177
|
+
### Outlet
|
338
178
|
|
339
179
|
```ts
|
340
|
-
interface
|
341
|
-
|
342
|
-
Params extends { [K: string]: string | undefined } = ExtractRouteParams<Path, string>
|
343
|
-
> {
|
344
|
-
location?: H.Location;
|
345
|
-
component?: React.ComponentType<RouteComponentProps<any>> | React.ComponentType<any>;
|
346
|
-
render?: (props: RouteComponentProps<Params>) => React.ReactNode;
|
347
|
-
children?: ((props: RouteChildrenProps<Params>) => React.ReactNode) | React.ReactNode;
|
348
|
-
path?: Path | Path[];
|
349
|
-
exact?: boolean;
|
350
|
-
sensitive?: boolean;
|
351
|
-
strict?: boolean;
|
180
|
+
interface OutletProps {
|
181
|
+
context?: unknown;
|
352
182
|
}
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
any
|
357
|
-
> {}
|
183
|
+
declare function Outlet(
|
184
|
+
props: OutletProps
|
185
|
+
): React.ReactElement | null;
|
358
186
|
```
|
359
187
|
|
360
|
-
|
361
|
-
|
362
|
-
#### component
|
363
|
-
|
364
|
-
类型: `React.ComponentType`
|
365
|
-
|
366
|
-
当路由匹配成功,会渲染传入 `component` 的组件。
|
188
|
+
An `<Outlet>` should be used in parent route elements to render their child route elements. This allows nested UI to show up when child routes are rendered.
|
367
189
|
|
368
190
|
```tsx
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
191
|
+
function Dashboard() {
|
192
|
+
return (
|
193
|
+
<div>
|
194
|
+
<h1>Dashboard</h1>
|
195
|
+
|
196
|
+
{/* This element will render either <DashboardMessages> when the URL is
|
197
|
+
"/messages", <DashboardTasks> at "/tasks", or null if it is "/"
|
198
|
+
*/}
|
199
|
+
<Outlet />
|
200
|
+
</div>
|
201
|
+
);
|
375
202
|
}
|
376
203
|
|
377
204
|
function App() {
|
378
|
-
return
|
205
|
+
return (
|
206
|
+
<Routes>
|
207
|
+
<Route path="/" element={<Dashboard />}>
|
208
|
+
<Route
|
209
|
+
path="messages"
|
210
|
+
element={<DashboardMessages />}
|
211
|
+
/>
|
212
|
+
<Route path="tasks" element={<DashboardTasks />} />
|
213
|
+
</Route>
|
214
|
+
</Routes>
|
215
|
+
);
|
379
216
|
}
|
380
217
|
```
|
381
218
|
|
382
|
-
|
383
|
-
如果 component 是一个 inline function,如 `<Route path="/user/:username" component={() => 'hello'} />`,因为每次 rerender 的时候,component 都会是一个新的 `type`,所以 component 组件会先 unmount,再 mount。我们需要避免这种写法,或者使用 render 代替 component。
|
384
|
-
:::
|
385
|
-
|
386
|
-
#### render
|
387
|
-
|
388
|
-
类型: `(props: RouteComponentProps<Params>) => React.ReactNode`
|
389
|
-
|
390
|
-
允许使用 `inline function` 进行渲染,同时不会有 `component` remounting 的问题。
|
391
|
-
|
392
|
-
```tsx
|
393
|
-
import React from "react";
|
394
|
-
import { Route } from "@modern-js/runtime/router";
|
219
|
+
### Route
|
395
220
|
|
396
|
-
|
397
|
-
|
221
|
+
```ts
|
222
|
+
interface RouteObject {
|
223
|
+
path?: string;
|
224
|
+
index?: boolean;
|
225
|
+
children?: React.ReactNode;
|
226
|
+
caseSensitive?: boolean;
|
227
|
+
id?: string;
|
228
|
+
loader?: LoaderFunction;
|
229
|
+
action?: ActionFunction;
|
230
|
+
element?: React.ReactNode | null;
|
231
|
+
errorElement?: React.ReactNode | null;
|
232
|
+
handle?: RouteObject["handle"];
|
233
|
+
shouldRevalidate?: ShouldRevalidateFunction;
|
398
234
|
}
|
399
235
|
```
|
400
236
|
|
401
|
-
|
402
|
-
component 的优先级高于 render。
|
403
|
-
:::
|
237
|
+
`Route` represents the route information. A `Route` object couples URL segments to components, data loading and data mutations.
|
404
238
|
|
405
|
-
|
239
|
+
`Route` can be used as a plain object, passing to the router creation functions:
|
406
240
|
|
407
|
-
|
241
|
+
```ts
|
242
|
+
const router = createBrowserRouter([
|
243
|
+
{
|
244
|
+
// it renders this element
|
245
|
+
element: <Team />,
|
246
|
+
|
247
|
+
// when the URL matches this segment
|
248
|
+
path: "teams/:teamId",
|
249
|
+
|
250
|
+
// with this data loaded before rendering
|
251
|
+
loader: async ({ request, params }) => {
|
252
|
+
return fetch(
|
253
|
+
`/fake/api/teams/${params.teamId}.json`,
|
254
|
+
{ signal: request.signal }
|
255
|
+
);
|
256
|
+
},
|
257
|
+
|
258
|
+
// performing this mutation when data is submitted to it
|
259
|
+
action: async ({ request }) => {
|
260
|
+
return updateFakeTeam(await request.formData());
|
261
|
+
},
|
262
|
+
|
263
|
+
// and renders this element in case something went wrong
|
264
|
+
errorElement: <ErrorBoundary />,
|
265
|
+
},
|
266
|
+
]);
|
267
|
+
```
|
408
268
|
|
409
|
-
|
269
|
+
You can also declare your routes with JSX and `createRoutesFromElements`, the props to the element are identical to the properties of the route objects:
|
410
270
|
|
411
|
-
```
|
412
|
-
|
413
|
-
|
271
|
+
```ts
|
272
|
+
const router = createBrowserRouter(
|
273
|
+
createRoutesFromElements(
|
414
274
|
<Route
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
275
|
+
element={<Team />}
|
276
|
+
path="teams/:teamId"
|
277
|
+
loader={async ({ params }) => {
|
278
|
+
return fetch(
|
279
|
+
`/fake/api/teams/${params.teamId}.json`
|
280
|
+
);
|
281
|
+
}}
|
282
|
+
action={async ({ request }) => {
|
283
|
+
return updateFakeTeam(await request.formData());
|
284
|
+
}}
|
285
|
+
errorElement={<ErrorBoundary />}
|
421
286
|
/>
|
422
|
-
)
|
423
|
-
|
424
|
-
|
425
|
-
function App() {
|
426
|
-
return <ul>
|
427
|
-
<ListItemLink to="/somewhere" />
|
428
|
-
<ListItemLink to="/somewhere-else" />
|
429
|
-
</ul>;
|
430
|
-
}
|
431
|
-
```
|
432
|
-
|
433
|
-
#### path
|
434
|
-
|
435
|
-
类型: `string | string[]`
|
436
|
-
|
437
|
-
符合 [path-to-regexp@^1.7.0](https://github.com/pillarjs/path-to-regexp/tree/v1.7.0) 匹配规则的 url 字符串或数组。
|
438
|
-
|
439
|
-
```tsx
|
440
|
-
<Route path="/users/:id">
|
441
|
-
<User />
|
442
|
-
</Route>
|
443
|
-
|
444
|
-
<Route path={["/users/:id", "/profile/:id"]}>
|
445
|
-
<User />
|
446
|
-
</Route>
|
287
|
+
)
|
288
|
+
);
|
447
289
|
```
|
448
290
|
|
449
|
-
|
450
|
-
|
451
|
-
类型: `boolean`
|
452
|
-
|
453
|
-
默认值: `false`
|
454
|
-
|
455
|
-
当 `exact` 值为 `true` 时,会进行准确匹配。
|
456
|
-
|
457
|
-
| path | location.pathname | exact | matches? |
|
458
|
-
| - | - | - | - |
|
459
|
-
| /one | /one/two | true | no |
|
460
|
-
| /one | /one/two | false | yes |
|
461
|
-
|
462
|
-
|
463
|
-
#### strict
|
464
|
-
|
465
|
-
类型: `boolean`
|
466
|
-
|
467
|
-
默认值: `false`
|
468
|
-
|
469
|
-
当 `strict` 值为 `true` 时,会进行严格匹配。若 `path` 以 '/' 结尾,那么 `location.pathname` 也需要以 '/' 结尾,才能匹配。
|
470
|
-
|
471
|
-
| path | location.pathname | matches? |
|
472
|
-
| - | - | - |
|
473
|
-
| /one/ | /one | no |
|
474
|
-
| /one/ | /one/ | yes |
|
475
|
-
| /one/| /one/two | yes |
|
476
|
-
|
477
|
-
#### sensitive
|
478
|
-
|
479
|
-
类型: `boolean`
|
480
|
-
|
481
|
-
默认值: `false`
|
482
|
-
|
483
|
-
当 `sensitive` 设置为 `true`,则 path 大小写不敏感。
|
484
|
-
|
485
|
-
#### location
|
486
|
-
|
487
|
-
类型: `object`
|
291
|
+
## More
|
488
292
|
|
489
|
-
|
293
|
+
You can access to [React Router](https://reactrouter.com/) to get the full API information.
|
490
294
|
|
491
|
-
若想要了解更多的底层 API 信息,可至 [react-router 官网](https://reactrouter.com/web/guides/start) 查看。
|
492
295
|
|