@modern-js/main-doc 2.0.0-canary.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/_category_.json +1 -1
  3. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/use-module-apps.md +62 -31
  4. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/router/router.md +174 -375
  5. package/en/docusaurus-plugin-content-docs/current/components/enable-micro-frontend.md +13 -0
  6. package/en/docusaurus-plugin-content-docs/current/components/micro-master-manifest-config.md +15 -0
  7. package/en/docusaurus-plugin-content-docs/current/components/micro-runtime-config.md +18 -0
  8. package/en/docusaurus-plugin-content-docs/current/components/router-legacy-tip.md +1 -0
  9. package/en/docusaurus-plugin-content-docs/current/configure/app/auto-load-plugin.md +62 -0
  10. package/en/docusaurus-plugin-content-docs/current/configure/app/deploy/microFrontend.md +54 -0
  11. package/en/docusaurus-plugin-content-docs/current/configure/app/output/ssg.md +226 -0
  12. package/en/docusaurus-plugin-content-docs/current/configure/app/runtime/master-app.md +20 -39
  13. package/en/docusaurus-plugin-content-docs/current/configure/app/runtime/router.md +17 -4
  14. package/en/docusaurus-plugin-content-docs/current/configure/app/runtime/state.md +17 -4
  15. package/en/docusaurus-plugin-content-docs/current/configure/app/server/enable-framework-ext.md +47 -0
  16. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/bff/function.md +2 -2
  17. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/ssg.md +6 -2
  18. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/_category_.json +4 -0
  19. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/data-fetch.md +1 -1
  20. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/routes.md +0 -2
  21. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/_category_.json +5 -0
  22. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/extend.md +162 -0
  23. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/hook-list.md +803 -0
  24. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/hook.md +169 -0
  25. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/implement.md +247 -0
  26. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/introduction.md +49 -0
  27. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/plugin-api.md +116 -0
  28. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/relationship.md +118 -0
  29. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/common.md +1 -1
  30. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/module.md +3 -1
  31. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/mwa.md +1 -9
  32. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/project.md +2 -2
  33. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/micro-frontend/_category_.json +4 -0
  34. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/micro-frontend/c01-introduction.md +29 -0
  35. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/micro-frontend/c02-development.md +191 -0
  36. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/micro-frontend/c03-main-app.md +246 -0
  37. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/micro-frontend/c04-communicate.md +54 -0
  38. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/micro-frontend/c05-mixed-stack.md +24 -0
  39. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/_category_.json +4 -0
  40. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/auto-actions.md +90 -0
  41. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/computed-state.md +151 -0
  42. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/define-model.md +66 -0
  43. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/faq.md +43 -0
  44. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/manage-effects.md +259 -0
  45. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/model-communicate.md +219 -0
  46. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/performance.md +173 -0
  47. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/quick-start.md +116 -0
  48. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/redux-integration.md +21 -0
  49. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/test-model.md +43 -0
  50. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/typescript-best-practice.md +71 -0
  51. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/use-model.md +244 -0
  52. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/use-out-of-modernjs.md +51 -0
  53. package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/_category_.json +5 -0
  54. package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c01-start.md +99 -0
  55. package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c02-component.md +56 -0
  56. package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c03-css.md +324 -0
  57. package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c04-routes.md +169 -0
  58. package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c05-loader.md +82 -0
  59. package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c06-model.md +260 -0
  60. package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c07-container.md +283 -0
  61. package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c08-entries.md +137 -0
  62. package/en/docusaurus-plugin-content-docs/current/tutorials/foundations/_category_.json +1 -1
  63. package/en/docusaurus-plugin-content-docs/current/tutorials/foundations/introduction.md +5 -3
  64. package/package.json +4 -4
  65. package/zh/apis/app/runtime/core/use-module-apps.md +2 -0
  66. package/zh/apis/app/runtime/router/router.md +169 -371
  67. package/zh/components/micro-master-manifest-config.md +15 -0
  68. package/zh/components/router-legacy-tip.md +1 -0
  69. package/zh/configure/app/auto-load-plugin.md +62 -0
  70. package/zh/configure/app/deploy/microFrontend.md +0 -10
  71. package/zh/configure/app/output/ssg.md +1 -5
  72. package/zh/configure/app/runtime/master-app.md +4 -18
  73. package/zh/configure/app/runtime/router.md +19 -4
  74. package/zh/configure/app/runtime/state.md +7 -7
  75. package/zh/configure/app/server/enable-framework-ext.md +47 -0
  76. package/zh/configure/app/server/port.md +1 -1
  77. package/zh/configure/app/tools/_category_.json +1 -1
  78. package/zh/guides/advanced-features/eslint.md +2 -1
  79. package/zh/guides/advanced-features/ssg.md +4 -0
  80. package/zh/guides/basic-features/data-fetch.md +1 -1
  81. package/zh/guides/basic-features/env-vars.md +1 -1
  82. package/zh/guides/basic-features/routes.md +0 -3
  83. package/zh/guides/topic-detail/generator/config/module.md +3 -1
  84. package/zh/guides/topic-detail/generator/config/mwa.md +1 -9
  85. package/zh/guides/topic-detail/model/quick-start.md +1 -1
  86. package/zh/tutorials/first-app/c06-model.md +5 -1
  87. package/zh/tutorials/first-app/c08-entries.md +1 -1
  88. package/zh/tutorials/foundations/introduction.md +5 -3
  89. package/en/docusaurus-plugin-content-docs/current/apis/app/overview.md +0 -12
  90. package/en/docusaurus-plugin-content-docs/current/configure/app/bff/fetcher.md +0 -28
  91. package/en/docusaurus-plugin-content-docs/current/configure/app/dev/with-master-app.md +0 -31
  92. package/en/docusaurus-plugin-content-docs/current/guides/overview.md +0 -11
  93. package/en/docusaurus-plugin-content-docs/current/tutorials/foundations/basic.md +0 -8
  94. package/zh/apis/app/overview.md +0 -11
  95. package/zh/apis/monorepo/overview.md +0 -11
  96. package/zh/configure/app/bff/fetcher.md +0 -31
  97. package/zh/configure/app/dev/with-master-app.md +0 -32
  98. package/zh/guides/overview.md +0 -11
  99. package/zh/tutorials/foundations/basic.md +0 -8
@@ -3,32 +3,40 @@ title: router
3
3
  sidebar_position: 1
4
4
  ---
5
5
 
6
- :::info 补充信息
7
- 基于 [react-router](https://reactrouter.com/web/guides/start) 的路由解决方案。
8
- :::
9
-
10
- :::caution 注意
11
- 使用该 API 前,请确认没有禁用 [router 插件](#)。
6
+ :::info
7
+ The router solution based on [react-router 6](https://reactrouter.com/).
12
8
  :::
13
9
 
14
10
  ## hooks
15
11
 
16
- ### useHistory
12
+ ### useNavigate
17
13
 
18
14
  ```ts
19
- function useHistory<HistoryLocationState = H.LocationState>(): H.History<HistoryLocationState>;
15
+ declare function useNavigate(): NavigateFunction;
16
+
17
+ interface NavigateFunction {
18
+ (
19
+ to: To,
20
+ options?: {
21
+ replace?: boolean;
22
+ state?: any;
23
+ relative?: RelativeRoutingType;
24
+ }
25
+ ): void;
26
+ (delta: number): void;
27
+ }
20
28
  ```
21
29
 
22
- 用于获取 `history` 实例。
30
+ The `useNavigate` hook returns a function that lets you navigate programmatically。
23
31
 
24
32
  ```tsx
25
- import { useHistory } from "@modern-js/runtime/router";
33
+ import { useNavigate } from "@modern-js/runtime/router";
26
34
 
27
35
  export function HomeButton() {
28
- let history = useHistory();
36
+ let navigate = useNavigate();
29
37
 
30
38
  function handleClick() {
31
- history.push("/home");
39
+ navigate("/home");
32
40
  }
33
41
 
34
42
  return (
@@ -42,20 +50,18 @@ export function HomeButton() {
42
50
  ### useLocation
43
51
 
44
52
  ```ts
45
- function useLocation<S = H.LocationState>(): H.Location<S>;
53
+ declare function useLocation(): Location;
54
+
55
+ interface Location extends Path {
56
+ state: unknown;
57
+ key: Key;
58
+ }
46
59
  ```
47
60
 
48
- `useLocation` 返回当前 url 对应的 [location](https://reactrouter.com/web/api/location) 对象。每当路由更新的时候,都会拿到一个新的 `location` 对象。
61
+ 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
62
 
50
63
  ```ts
51
- import React from "react";
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";
64
+ import { useLocation } from "@modern-js/runtime/router";
59
65
 
60
66
  function usePageViews() {
61
67
  let location = useLocation();
@@ -66,26 +72,25 @@ function usePageViews() {
66
72
 
67
73
  function App() {
68
74
  usePageViews();
69
- return <Switch>...</Switch>;
75
+ return (
76
+ //...
77
+ );
70
78
  }
71
79
  ```
72
80
 
73
81
  ### useParams
74
82
 
75
83
  ```ts
76
- function useParams<
77
- Params extends {
78
- [K in keyof Params]?: string
79
- } = {}
80
- >(): Params;
84
+ declare function useParams<
85
+ K extends string = string
86
+ >(): Readonly<Params<K>>;
81
87
  ```
82
88
 
83
- `useParams` 返回一个 key/value 的键值对表示路由中的参数信息。它等同于 `<Route >` 组件中的 `match.params` 值。
89
+ 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
90
 
85
91
  ```tsx
86
- import React from "react";
87
92
  import {
88
- Switch,
93
+ Routes,
89
94
  Route,
90
95
  useParams
91
96
  } from "@modern-js/runtime/router";
@@ -96,397 +101,191 @@ function BlogPost() {
96
101
  }
97
102
 
98
103
  function App() {
99
- return <Switch>
100
- <Route exact path="/">
101
- <div>home</div>
102
- </Route>
103
- <Route path="/blog/:slug">
104
- <BlogPost />
105
- </Route>
106
- </Switch>
104
+ return (
105
+ <Routes>
106
+ <Route path="/" element={ <div>home</div> } />
107
+ <Route path="/blog/:slug" element={ <BlogPost />}/>
108
+ </Routes>
109
+ )
107
110
  }
108
111
  ```
109
112
 
110
- ### useRouteMatch
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
-
113
+ ## Components
129
114
 
130
115
  ### Link
131
116
 
132
117
  ```ts
133
- interface Link<S = H.LocationState>
134
- extends React.ForwardRefExoticComponent<
135
- React.PropsWithoutRef<LinkProps<S>> & React.RefAttributes<HTMLAnchorElement>
136
- > {}
137
- ```
138
-
139
- 可以使用 `Link` 组件进行路由跳转。
118
+ declare function Link(props: LinkProps): React.ReactElement;
119
+
120
+ interface LinkProps
121
+ extends Omit<
122
+ React.AnchorHTMLAttributes<HTMLAnchorElement>,
123
+ "href"
124
+ > {
125
+ replace?: boolean;
126
+ state?: any;
127
+ to: To;
128
+ reloadDocument?: boolean;
129
+ }
140
130
 
141
- ```ts
142
- <Link to="/about">About</Link>
131
+ type To = string | Partial<Path>;
143
132
  ```
144
133
 
145
- #### LinkProps
146
-
147
- **to**
148
-
149
- 类型: `string | object | function`
150
-
151
- `string`
134
+ A `<Link>` is an element that lets the user navigate to another page by clicking or tapping on it.
152
135
 
153
136
  ```ts
154
- <Link to="/courses?sort=name" />
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} />
137
+ <Link to="/about">About</Link>
196
138
  ```
197
139
 
198
140
  ### NavLink
199
141
 
200
142
  ```ts
201
- interface NavLink<S = H.LocationState>
202
- extends React.ForwardRefExoticComponent<
203
- React.PropsWithoutRef<NavLinkProps<S>> & React.RefAttributes<HTMLAnchorElement>
204
- > {}
205
- ```
206
-
207
- `NavLink` 是一种特殊的 [Link](#link) 组件,当 `NavLink` 对应路由匹配到当前 `url`, 会给 `NavLink` 所渲染的元素添加一些额外的样式。
208
-
209
-
210
- #### NavLinkProps
211
-
212
- **activeClassName**
213
-
214
- 类型: `string`
215
-
216
- 设置路由匹配时额外 class。
217
-
218
- ```tsx
219
- <NavLink to="/faq" activeClassName="selected">
220
- FAQs
221
- </NavLink>
222
- ```
223
-
224
- **activeStyle**
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;
143
+ declare function NavLink(
144
+ props: NavLinkProps
145
+ ): React.ReactElement;
146
+
147
+ interface NavLinkProps
148
+ extends Omit<
149
+ LinkProps,
150
+ "className" | "style" | "children"
151
+ > {
152
+ caseSensitive?: boolean;
153
+ children?:
154
+ | React.ReactNode
155
+ | ((props: { isActive: boolean }) => React.ReactNode);
156
+ className?:
157
+ | string
158
+ | ((props: {
159
+ isActive: boolean;
160
+ }) => string | undefined);
161
+ end?: boolean;
162
+ style?:
163
+ | React.CSSProperties
164
+ | ((props: {
165
+ isActive: boolean;
166
+ }) => React.CSSProperties);
294
167
  }
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
168
  ```
307
169
 
308
- #### PromptProps
309
-
310
- **message**
311
-
312
- 类型: `string` | `function`
170
+ A `<NavLink>` is a special kind of `<Link>` that knows whether or not it is "active".
313
171
 
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
- ```
329
172
 
330
- **when**
331
-
332
- 类型: `boolean`
333
-
334
- 当 `when` 为 `true` 时,才会在页面跳转前展示二次确认提示。
335
-
336
-
337
- ### Route
173
+ ### Outlet
338
174
 
339
175
  ```ts
340
- interface RouteProps<
341
- Path extends string = string,
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;
176
+ interface OutletProps {
177
+ context?: unknown;
352
178
  }
353
-
354
- class Route<T extends {} = {}, Path extends string = string> extends React.Component<
355
- RouteProps<Path> & OmitNative<T, keyof RouteProps>,
356
- any
357
- > {}
179
+ declare function Outlet(
180
+ props: OutletProps
181
+ ): React.ReactElement | null;
358
182
  ```
359
183
 
360
- `Route` 组件用于定义路由。
361
-
362
- #### component
363
-
364
- 类型: `React.ComponentType`
365
-
366
- 当路由匹配成功,会渲染传入 `component` 的组件。
184
+ 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
185
 
368
186
  ```tsx
369
- import React from "react";
370
- import { Route } from "@modern-js/runtime/router";
371
-
372
- // All route props (match, location and history) are available to User
373
- function User(props) {
374
- return <h1>Hello {props.match.params.username}!</h1>;
187
+ function Dashboard() {
188
+ return (
189
+ <div>
190
+ <h1>Dashboard</h1>
191
+
192
+ {/* This element will render either <DashboardMessages> when the URL is
193
+ "/messages", <DashboardTasks> at "/tasks", or null if it is "/"
194
+ */}
195
+ <Outlet />
196
+ </div>
197
+ );
375
198
  }
376
199
 
377
200
  function App() {
378
- return <Route path="/user/:username" component={User} />;
201
+ return (
202
+ <Routes>
203
+ <Route path="/" element={<Dashboard />}>
204
+ <Route
205
+ path="messages"
206
+ element={<DashboardMessages />}
207
+ />
208
+ <Route path="tasks" element={<DashboardTasks />} />
209
+ </Route>
210
+ </Routes>
211
+ );
379
212
  }
380
213
  ```
381
214
 
382
- :::tip 提示
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";
215
+ ### Route
395
216
 
396
- function App() {
397
- <Route path="/home" render={() => <div>Home</div>} />
217
+ ```ts
218
+ interface RouteObject {
219
+ path?: string;
220
+ index?: boolean;
221
+ children?: React.ReactNode;
222
+ caseSensitive?: boolean;
223
+ id?: string;
224
+ loader?: LoaderFunction;
225
+ action?: ActionFunction;
226
+ element?: React.ReactNode | null;
227
+ errorElement?: React.ReactNode | null;
228
+ handle?: RouteObject["handle"];
229
+ shouldRevalidate?: ShouldRevalidateFunction;
398
230
  }
399
231
  ```
400
232
 
401
- :::info
402
- component 的优先级高于 render。
403
- :::
233
+ `Route` represents the route information. A `Route` object couples URL segments to components, data loading and data mutations.
404
234
 
405
- #### children
235
+ `Route` can be used as a plain object, passing to the router creation functions:
406
236
 
407
- 类型: `((props: RouteChildrenProps<Params>) => React.ReactNode) | React.ReactNode`
237
+ ```ts
238
+ const router = createBrowserRouter([
239
+ {
240
+ // it renders this element
241
+ element: <Team />,
242
+
243
+ // when the URL matches this segment
244
+ path: "teams/:teamId",
245
+
246
+ // with this data loaded before rendering
247
+ loader: async ({ request, params }) => {
248
+ return fetch(
249
+ `/fake/api/teams/${params.teamId}.json`,
250
+ { signal: request.signal }
251
+ );
252
+ },
253
+
254
+ // performing this mutation when data is submitted to it
255
+ action: async ({ request }) => {
256
+ return updateFakeTeam(await request.formData());
257
+ },
258
+
259
+ // and renders this element in case something went wrong
260
+ errorElement: <ErrorBoundary />,
261
+ },
262
+ ]);
263
+ ```
408
264
 
409
- 如果在路由匹配或不匹配的情况下,都需要渲染一些内容,那么可以使用 `children` 参数。
265
+ 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
266
 
411
- ```tsx
412
- function ListItemLink({ to, ...rest }) {
413
- return (
267
+ ```ts
268
+ const router = createBrowserRouter(
269
+ createRoutesFromElements(
414
270
  <Route
415
- path={to}
416
- children={({ match }) => (
417
- <li className={match ? "active" : ""}>
418
- <Link to={to} {...rest} />
419
- </li>
420
- )}
271
+ element={<Team />}
272
+ path="teams/:teamId"
273
+ loader={async ({ params }) => {
274
+ return fetch(
275
+ `/fake/api/teams/${params.teamId}.json`
276
+ );
277
+ }}
278
+ action={async ({ request }) => {
279
+ return updateFakeTeam(await request.formData());
280
+ }}
281
+ errorElement={<ErrorBoundary />}
421
282
  />
422
- );
423
- }
424
-
425
- function App() {
426
- return <ul>
427
- <ListItemLink to="/somewhere" />
428
- <ListItemLink to="/somewhere-else" />
429
- </ul>;
430
- }
283
+ )
284
+ );
431
285
  ```
432
286
 
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>
447
- ```
448
-
449
- #### exact
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`
287
+ ## More
488
288
 
489
- ## 更多底层 API
289
+ You can access to [React Router](https://reactrouter.com/) to get the full API information.
490
290
 
491
- 若想要了解更多的底层 API 信息,可至 [react-router 官网](https://reactrouter.com/web/guides/start) 查看。
492
291
 
@@ -0,0 +1,13 @@
1
+ ```javascript title="modern.config.ts"
2
+ import AppToolPlugin, { defineConfig } from '@modern-js/app-tools';
3
+ import GarfishPlugin from '@modern-js/plugin-garfish';
4
+
5
+ export default defineConfig({
6
+ runtime: {
7
+ router: true,
8
+ state: true,
9
+ masterApp: true,
10
+ },
11
+ plugins: [AppToolPlugin(), GarfishPlugin()],
12
+ });
13
+ ```
@@ -0,0 +1,15 @@
1
+ ## manifest
2
+
3
+ ```ts
4
+ interface Manifest {
5
+ getAppList?: ()=> Array<AppInfo>
6
+ }
7
+ ```
8
+
9
+ ### getAppList?
10
+
11
+ Through the `getAppList` configuration, you can customize how to get remote list data
12
+
13
+ ```ts
14
+ type GetAppList = ()=> Promise<Array<AppInfo>>;
15
+ ```
@@ -0,0 +1,18 @@
1
+ ```javascript title="src/App.tsx"
2
+ import { defineConfig } from '@modern-js/runtime';
3
+
4
+ defineConfig(App, {
5
+ masterApp: {
6
+ apps: [
7
+ {
8
+ name: 'DashBoard',
9
+ entry: 'http://127.0.0.1:8081/',
10
+ },
11
+ {
12
+ name: 'TableList',
13
+ entry: 'http://localhost:8082',
14
+ },
15
+ ],
16
+ },
17
+ });
18
+ ```