@modern-js/main-doc 0.0.0-next-1685383616364 → 0.0.0-next-1685436485731

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.
Files changed (86) hide show
  1. package/CHANGELOG.md +7 -2
  2. package/docs/en/apis/app/commands.mdx +5 -5
  3. package/docs/en/apis/app/hooks/api/api.mdx +80 -0
  4. package/docs/en/apis/app/hooks/api/app.mdx +12 -0
  5. package/docs/en/apis/app/hooks/api/lambda.mdx +57 -0
  6. package/docs/en/apis/app/hooks/api/test.mdx +1 -1
  7. package/docs/en/apis/app/hooks/config/html.mdx +2 -2
  8. package/docs/en/apis/app/hooks/config/icon.mdx +19 -19
  9. package/docs/en/apis/app/hooks/config/mock.mdx +1 -1
  10. package/docs/en/apis/app/hooks/config/public.mdx +10 -10
  11. package/docs/en/apis/app/hooks/config/storybook.mdx +3 -3
  12. package/docs/en/apis/app/hooks/config/upload.mdx +13 -13
  13. package/docs/en/apis/app/hooks/modern-config.mdx +4 -4
  14. package/docs/en/apis/app/hooks/server/index_.mdx +2 -9
  15. package/docs/en/apis/app/hooks/server/test.mdx +5 -2
  16. package/docs/en/apis/app/hooks/shared.mdx +1 -1
  17. package/docs/en/apis/app/hooks/src/app.mdx +17 -27
  18. package/docs/en/apis/app/hooks/src/index_.mdx +6 -6
  19. package/docs/en/apis/app/hooks/src/pages.mdx +41 -37
  20. package/docs/en/apis/app/hooks/src/routes.mdx +16 -36
  21. package/docs/en/apis/app/hooks/src/server.mdx +1 -1
  22. package/docs/en/apis/app/hooks/src/stories.mdx +6 -3
  23. package/docs/en/apis/app/hooks/src/test.mdx +4 -3
  24. package/docs/en/apis/app/runtime/web-server/hook.mdx +2 -2
  25. package/docs/en/apis/app/runtime/web-server/middleware.mdx +2 -2
  26. package/docs/en/components/init-app.mdx +3 -3
  27. package/docs/en/components/init-rspack-app.mdx +4 -4
  28. package/docs/en/components/ua-polyfill.mdx +2 -2
  29. package/docs/en/configure/app/tools/swc.mdx +2 -2
  30. package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -2
  31. package/docs/en/guides/advanced-features/bff/function.mdx +4 -4
  32. package/docs/en/guides/advanced-features/bff/type.mdx +5 -5
  33. package/docs/en/guides/advanced-features/rspack-start.mdx +2 -2
  34. package/docs/en/guides/advanced-features/ssg.mdx +2 -2
  35. package/docs/en/guides/advanced-features/testing.mdx +2 -2
  36. package/docs/en/guides/advanced-features/web-server.mdx +2 -2
  37. package/docs/en/guides/basic-features/css.mdx +2 -2
  38. package/docs/en/guides/basic-features/routes.mdx +11 -7
  39. package/docs/en/guides/concept/entries.mdx +3 -3
  40. package/docs/en/guides/topic-detail/generator/codesmith/develop.mdx +3 -3
  41. package/docs/en/guides/topic-detail/generator/plugin/develop.mdx +13 -13
  42. package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +8 -8
  43. package/docs/en/tutorials/first-app/c03-css.mdx +2 -2
  44. package/docs/en/tutorials/first-app/c08-entries.mdx +3 -3
  45. package/docs/zh/apis/app/commands.mdx +3 -3
  46. package/docs/zh/apis/app/hooks/api/{functions/api.mdx → api.mdx} +4 -4
  47. package/docs/zh/apis/app/hooks/api/app.mdx +12 -0
  48. package/docs/zh/apis/app/hooks/api/{framework/lambda.mdx → lambda.mdx} +5 -5
  49. package/docs/zh/apis/app/hooks/api/test.mdx +3 -3
  50. package/docs/zh/apis/app/hooks/config/icon.mdx +15 -15
  51. package/docs/zh/apis/app/hooks/config/mock.mdx +1 -1
  52. package/docs/zh/apis/app/hooks/config/public.mdx +3 -3
  53. package/docs/zh/apis/app/hooks/config/upload.mdx +1 -1
  54. package/docs/zh/apis/app/hooks/modern-config.mdx +3 -3
  55. package/docs/zh/apis/app/hooks/server/index_.mdx +1 -6
  56. package/docs/zh/apis/app/hooks/shared.mdx +1 -1
  57. package/docs/zh/apis/app/hooks/src/app.mdx +15 -25
  58. package/docs/zh/apis/app/hooks/src/index_.mdx +6 -6
  59. package/docs/zh/apis/app/hooks/src/pages.mdx +7 -3
  60. package/docs/zh/apis/app/hooks/src/routes.mdx +4 -4
  61. package/docs/zh/apis/app/hooks/src/stories.mdx +1 -1
  62. package/docs/zh/components/ua-polyfill.mdx +1 -1
  63. package/docs/zh/configure/app/tools/swc.mdx +2 -2
  64. package/docs/zh/guides/advanced-features/rspack-start.mdx +2 -2
  65. package/docs/zh/guides/advanced-features/ssg.mdx +1 -1
  66. package/docs/zh/guides/advanced-features/testing.mdx +2 -2
  67. package/docs/zh/guides/advanced-features/web-server.mdx +1 -1
  68. package/docs/zh/guides/basic-features/css.mdx +1 -1
  69. package/docs/zh/guides/basic-features/routes.mdx +7 -4
  70. package/docs/zh/guides/concept/entries.mdx +3 -3
  71. package/docs/zh/guides/topic-detail/generator/plugin/develop.mdx +14 -14
  72. package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +4 -4
  73. package/docs/zh/guides/topic-detail/model/test-model.mdx +1 -1
  74. package/docs/zh/tutorials/first-app/c03-css.mdx +1 -1
  75. package/docs/zh/tutorials/first-app/c08-entries.mdx +1 -1
  76. package/package.json +5 -5
  77. package/docs/en/apis/app/hooks/api/framework/_category_.json +0 -4
  78. package/docs/en/apis/app/hooks/api/framework/lambda.mdx +0 -57
  79. package/docs/en/apis/app/hooks/api/functions/_category_.json +0 -4
  80. package/docs/en/apis/app/hooks/api/functions/api.mdx +0 -81
  81. package/docs/en/apis/app/hooks/api/functions/app.mdx +0 -12
  82. package/docs/en/apis/app/hooks/api/functions/common.mdx +0 -9
  83. package/docs/zh/apis/app/hooks/api/framework/_category_.json +0 -4
  84. package/docs/zh/apis/app/hooks/api/functions/_category_.json +0 -4
  85. package/docs/zh/apis/app/hooks/api/functions/app.mdx +0 -12
  86. package/docs/zh/apis/app/hooks/api/functions/common.mdx +0 -9
@@ -4,11 +4,15 @@ sidebar_position: 3
4
4
  ---
5
5
  # pages/
6
6
 
7
- Entry identifier if the application want uses file system-based routing.
7
+ The identifier for the entry point when the application uses the [`Pages` entry](https://modernjs.dev/v1/docs/guides/usages/entries#pages-%E5%85%A5%E5%8F%A3) type.
8
8
 
9
- When the entry is the **Pages entry** type, the files in the `pages/` directory will be analyzed to client side routing.
9
+ :::info
10
+ Compatible with Modern.js 1.0 `Pages` entry. It is recommended to use [conventional routing](guides/basic-features/routes.html#conventional-routing).
11
+ :::
12
+
13
+ When the project structure is of the `Pages entry` type, the client-side routing configuration will be obtained by analyzing the files in the `src/pages` directory.
10
14
 
11
- For example, the following directory:
15
+ For example, the following directory structure:
12
16
 
13
17
  ```bash
14
18
  .
@@ -20,7 +24,7 @@ For example, the following directory:
20
24
  └── info.jsx
21
25
  ```
22
26
 
23
- The generated route is configured as:
27
+ The corresponding generated routing configuration is:
24
28
 
25
29
  ```bash
26
30
  [
@@ -30,22 +34,22 @@ The generated route is configured as:
30
34
  ]
31
35
  ```
32
36
 
33
- Files match the following conditions will not be treated as routing files:
37
+ Files under the pages directory that meet the following conditions will not be treated as routing files:
34
38
 
35
- - suffix is not `.(j|t)sx?`.
36
- - `.d.ts` type definition file.
37
- - test file suffix like `.(test|spec|e2e).(j|t)sx?`.
39
+ - Files whose suffix is not `.(j|t)sx?`.
40
+ - `.d.ts` type definition files.
41
+ - Test files ending in `.test.(j|t)sx?` or `.spec.(j|t)sx?` or `.e2e.(j|t)sx?`.
38
42
 
39
43
  :::tip
40
- it is recommended to write only the routing files in the `pages/`, and write the business logic to the independent features directory outside the `pages/`. In this way, most of the files in the pages directory will be routing files, and there is no need for additional filtering rules.
44
+ It is recommended to only write entry code in the pages directory and write business logic in the independent features directory outside the pages directory. In this way, most of the files under the pages directory will be routing files, and there is no need for additional filtering rules.
41
45
 
42
46
  :::
43
47
 
44
48
  ### Dynamic Routing
45
49
 
46
- Directories or files wrapped with `[]` are considered dynamic routing.
50
+ If the directory name of the route file is named with [], the generated route will be used as a dynamic route.
47
51
 
48
- For example the following directory structure:
52
+ For example, the following directory structure:
49
53
 
50
54
  ```bash
51
55
  .
@@ -60,7 +64,7 @@ For example the following directory structure:
60
64
  └── info.jsx
61
65
  ```
62
66
 
63
- The generated route is configured as:
67
+ The corresponding generated routing configuration is:
64
68
 
65
69
  ```js
66
70
  [
@@ -72,13 +76,13 @@ The generated route is configured as:
72
76
  ]
73
77
  ```
74
78
 
75
- Basis dynamic routing, it supports adding special routing suffixes `(*、?、+)`.
79
+ On the basis of dynamic routing, special routing suffixes `(*, ?, +)` can be added.
76
80
 
77
- For example: `src/pages/users/[id]*.tsx` generate route `/users/:id*`
81
+ For example: `src/pages/users/[id]*.tsx` will result in the route `/users/:id*`.
78
82
 
79
83
  ### Global Layout
80
84
 
81
- When the entire App needs a global `layout`, it can be achieved through `pages/_app.tsx`, which as follows:
85
+ When the entire application needs a global `layout`, it can be achieved through `pages/_app.tsx`. The specific writing method is as follows:
82
86
 
83
87
  ```js
84
88
  import React from 'react';
@@ -93,9 +97,9 @@ export const App = ({Component, ...pageProps}:{ Component: React.ComponentType})
93
97
  }
94
98
  ```
95
99
 
96
- The above `Component` is the component to which the route is accessed.
100
+ The above `Component` is the component matched when accessing a specific route.
97
101
 
98
- For example the following directory structure:
102
+ For example, the following directory structure:
99
103
 
100
104
  ```bash
101
105
  .
@@ -107,26 +111,26 @@ For example the following directory structure:
107
111
  └── index.js
108
112
  ```
109
113
 
110
- - access `/`, the `Component` is `pages/index.js`.
111
- - access `/a`, the `Component` is `pages/a/index.js`.
112
- - access `/a/b`, the `Component` is `pages/a/b/index.js`.
114
+ - Accessing `/` corresponds to the `Component` component in `pages/index.js`.
115
+ - Accessing `/a` corresponds to the `Component` component in `pages/a/index.js`.
116
+ - Accessing `/a/b` corresponds to the `Component` component in `pages/a/b/index.js`.
113
117
 
114
- :::tip Advantages
118
+ :::tip Advantages of global layout
115
119
 
116
- - preserve the state of the global layout when the page changes.
117
- - add global css.
118
- - handle ComponentDidCatch error
119
- - use [defineConfig](/apis/app/runtime/app/define-config) dynamic configuration runtime.
120
+ - Preserve the state of the global layout when the page changes.
121
+ - Add global styles.
122
+ - ComponentDidCatch error handling.
123
+ - Use [defineConfig](/apis/app/runtime/app/define-config) to dynamically configure the runtime configuration.
120
124
 
121
125
  :::
122
126
 
123
127
  ### Partial Layout
124
128
 
125
- When developing an App, where sub routes under the same route may share the layout.
129
+ When developing an application, there are scenarios where sub-routes under the same route share a layout.
126
130
 
127
- For this scene, Modern.js convention, when there is a `_layout.js` in the directory, the routes can shared this layout.
131
+ For this scenario, Modern.js conventionally has a similar effect to global layout when there is `_layout.js` under the directory.
128
132
 
129
- For example the following directory structure:
133
+ For example, the following directory structure:
130
134
 
131
135
  ```bash
132
136
  └── pages
@@ -147,18 +151,18 @@ const ALayout = ({ Component, ...pageProps }) => {
147
151
  export default ALayout;
148
152
  ```
149
153
 
150
- The Component props is the specific route, for example
154
+ The `Component` parameter is the component corresponding to a specific accessed route, for example:
151
155
 
152
- - access `/a`, the `Component` is `pages/a/index.js`.
153
- - 访问 `/a/b`, the `Component` is `pages/a/b/index.js`.
156
+ - Accessing `/a` corresponds to the `Component` component in `pages/a/index.js`.
157
+ - Accessing `/a/b` corresponds to the `Component` component in `pages/a/b/index.js`.
154
158
 
155
- In this way, you can use `pages/a/_layout.js` to display the routing common layout in the `a` directory.
159
+ In this way, `pages/a/_layout.js` can be used to meet the layout needs of shared routes under the `a` directory.
156
160
 
157
- ### 404 路由
161
+ ### 404 Route
158
162
 
159
- The convention `pages/404.[tj]sx` is the default 404 route.
163
+ `pages/404.[tj]sx` is conventionally the default 404 route.
160
164
 
161
- For example the following directory structure:
165
+ For example, the following directory structure:
162
166
 
163
167
  ```bash
164
168
  .
@@ -169,7 +173,7 @@ For example the following directory structure:
169
173
  ├── 404.js
170
174
  ```
171
175
 
172
- the generated route is configured is as:
176
+ The generated routing configuration is as follows:
173
177
 
174
178
  ```bash
175
179
  [
@@ -179,4 +183,4 @@ the generated route is configured is as:
179
183
  ]
180
184
  ```
181
185
 
182
- All unmatched routes will match to `pages/404.[tj]s`.
186
+ All unmatched routes will be matched to `pages/404.[tj]s`.
@@ -4,13 +4,13 @@ sidebar_position: 2
4
4
  ---
5
5
  # routes/
6
6
 
7
- The entry identifier when the application uses file system-based routing.
7
+ The identifier for the entry point when the application uses [Conventional Routing](guides/basic-features/routes.html#conventional-routing).
8
8
 
9
- When the project structure is of type `Routes directory entry`, the files in the `src/routes` directory are parsed to get the client-side routing configuration. See [Routing by convention](/guides/basic-features/routes) for more details on usage.
9
+ Conventional routing uses `routes/` as the convention for the entry point and analyzes the files in the `src/routes` directory to obtain the client-side routing configuration.
10
10
 
11
- Any `layout.[tj]sx` and `page.[tj]sx` under `src/routes` will be used as a route to the application:
11
+ Any `layout.[tj]sx` and `page.[tj]sx` under `src/routes` will be used as the application's routes:
12
12
 
13
- ```bash {3}
13
+ ```bash {3,4}
14
14
  .
15
15
  └── routes
16
16
  ├── layout.tsx
@@ -20,9 +20,9 @@ Any `layout.[tj]sx` and `page.[tj]sx` under `src/routes` will be used as a route
20
20
  └── page.tsx
21
21
  ```
22
22
 
23
- ## basic example
23
+ ## Basic Example
24
24
 
25
- The directory names in the `routes` directory will be used as a mapping of the route url, where `layout.tsx` is used as the layout component and `page.tsx` as the content component, which is a leaf node of the whole route, for example the following directory structure:
25
+ The directory name under `routes` will be used as the mapping of the route URL. `layout.tsx` is used as the layout component and `page.tsx` is used as the content component in the routing. They are the leaf nodes of the entire route. For example, the following directory structure:
26
26
 
27
27
  ```bash
28
28
  .
@@ -32,14 +32,14 @@ The directory names in the `routes` directory will be used as a mapping of the r
32
32
  └── page.tsx
33
33
  ```
34
34
 
35
- The following two routes are produced:
35
+ will generate two routes:
36
36
 
37
37
  - `/`
38
38
  - `/user`
39
39
 
40
- ## Dynamic Route
40
+ ## Dynamic Routing
41
41
 
42
- If the directory name of the route file is named with `[]`, the generated route will be used as a dynamic route. For example, the following file directories:
42
+ If the directory name of the route file is named with `[]`, the generated route will be used as a dynamic route. For example, the following file directory:
43
43
 
44
44
  ```
45
45
  └── routes
@@ -50,35 +50,15 @@ If the directory name of the route file is named with `[]`, the generated route
50
50
  └── page.tsx
51
51
  ```
52
52
 
53
- The `routes/[id]/page.tsx` file will be converted to a `/:id` route. All `/xxx` will match that route, except for the `/blog` route, which can be matched exactly.
53
+ The `routes/[id]/page.tsx` file will be converted to the `/:id` route. Except for the `/blog` route that can be matched exactly, all other `/xxx` routes will be matched to this route.
54
54
 
55
- In the component, you can get the corresponding parameters by [useParams](/apis/app/runtime/router/router#useparams).
55
+ In the component, you can use [useParams](/apis/app/runtime/router/router#useparams) to obtain the corresponding named parameter.
56
56
 
57
- In the loader, params will be used as input to [loader](/guides/basic-features/data-fetch#loader-function), and the corresponding parameters can be retrieved through the property `params`.
57
+ When using the [loader](/guides/basic-features/data-fetch#the-loader-function) function to obtain data, `params` will be passed as an input parameter to the `loader` function, and the corresponding parameter can be obtained through the attribute of `params`.
58
58
 
59
- ## Dynamic Optional Routes
59
+ ## Layout Component
60
60
 
61
- By using file directories named with `[$]`, the generated routes will be treated as dynamic routes. For example, the following file directory:
62
-
63
- ```
64
- └── routes
65
- ├── user
66
- │ └── [id$]
67
- │ └── page.tsx
68
- ├── blog
69
- │ └── page.tsx
70
- └── page.tsx
71
- ```
72
-
73
- The `routes/user/[id$]/page.tsx` file will be converted to the `/user/:id?` route. All routes under `/user` will match this route, and the `id` parameter is optional. This route is commonly used to differentiate between **creating** and **editing**.
74
-
75
- In the component, you can get the corresponding named parameters using [useParams](/apis/app/runtime/router/router#useparams).
76
-
77
- In the loader, params will be passed as an argument to the [loader](/guides/basic-features/data-fetch#loader-函数), and you can get them through `params.xxx`.
78
-
79
- ## Layout component
80
-
81
- As in the example below, you can add a common layout component for all routing components by adding `layout.tsx`
61
+ In the following example, a common layout component can be added to all route components by adding `layout.tsx`:
82
62
 
83
63
  ```bash
84
64
  .
@@ -90,7 +70,7 @@ As in the example below, you can add a common layout component for all routing c
90
70
  └── page.tsx
91
71
  ```
92
72
 
93
- You can represent child components in layout components by using `<Outlet>`:
73
+ In the layout component, you can use `<Outlet>` to represent the child components:
94
74
 
95
75
  ```tsx title=routes/layout.tsx
96
76
  import { Link, Outlet, useLoaderData } from '@modern-js/runtime/router';
@@ -105,6 +85,6 @@ export default () => {
105
85
  ```
106
86
 
107
87
  :::note
108
- `<Outlet>` is a new API in React Router 6, see [Outlet] for details(https://reactrouter.com/en/main/components/outlet#outlet).
88
+ `<Outlet>` is a new API in React Router 6. For details, see [Outlet](https://reactrouter.com/en/main/components/outlet#outlet).
109
89
 
110
90
  :::
@@ -4,4 +4,4 @@ sidebar_position: 8
4
4
  ---
5
5
  # *.[server|node].[tj]sx
6
6
 
7
- Used in application projects to place server side code, When `*.tsx` and `*. [server|node].tsx` coexist, rendering on the server side will give preference to the `*. [server|node].tsx` file instead of the `*.tsx` file.
7
+ Used in the application project to place server-side code. When `*.tsx` and `*.[server|node].tsx` coexist, SSR will prefer to use the `*.[server|node].tsx` file instead of the `*.tsx` file when rendering on the server.
@@ -4,11 +4,14 @@ sidebar_position: 7
4
4
  ---
5
5
  # **/*.stories.[tj]sx
6
6
 
7
- App Storybook debug file. files in `src/` which suffix `*.stories.[tj]sx` are as debug files for Storybook.
7
+ Application project Storybook files.
8
8
 
9
- Execute the `dev story` command to debugging these files in the Storybook.
9
+ You can create files in the `*.stories.[tj]sx` format in the project source code directory `src/` as Storybook files.
10
+
11
+ Run the `npm run dev story` command in the project to use these files to debug relevant content in Storybook.
10
12
 
11
13
  :::info
12
- Using a Storybook requires executing `new` command to enable the Visual Testing (Storybook) mode.
14
+ To use Storybook, you need to enable the "Visual Testing (Storybook)" mode by running the `new` command in the project first.
13
15
 
14
16
  :::
17
+
@@ -2,13 +2,14 @@
2
2
  title: '**/*.test.[tj]sx?'
3
3
  sidebar_position: 6
4
4
  ---
5
+
5
6
  # **/*.test.[tj]sx?
6
7
 
7
- App test file.
8
+ Application project test files.
8
9
 
9
- The App supports the file suffixed with `.test.[tj]sx` under the `src/` to write test cases.
10
+ The application project supports creating files with the suffix `.test.[tj]sx?` in the project source code directory (`src`) to write test cases.
10
11
 
11
12
  :::info
12
- To use unit test and integration test, you need to execute the `new` command in advance to enable the `unit test/integration test`.
13
+ To use unit testing and integration testing, you need to enable the "Unit Testing / Integration Testing" feature by running the `new` command in the project first.
13
14
 
14
15
  :::
@@ -24,8 +24,8 @@ Before using this API, please execute `pnpm run new` to create a new "Custom Web
24
24
 
25
25
  ```bash
26
26
  pnpm run new
27
- ? Action Create project element
28
- ? New "Custom Web Server" source code directory
27
+ ? Please select the operation you want: Create Elements
28
+ ? Please select the type of element to create: New "Custom Web Server" source code directory
29
29
  ```
30
30
 
31
31
  :::
@@ -27,8 +27,8 @@ Before using this API, please execute `pnpm run new` to create a new "Custom Web
27
27
 
28
28
  ```bash
29
29
  pnpm run new
30
- ? Action Create project element
31
- ? New "Custom Web Server" source code directory
30
+ ? Please select the operation you want: Create Element
31
+ ? Please select the type of element to create: New "Custom Web Server" source code directory
32
32
  ```
33
33
 
34
34
  :::
@@ -1,9 +1,9 @@
1
1
  Modern.js generator will provide an interactive Q & A interface, initialization items according to the result, according to the default selection:
2
2
 
3
3
  ```bash
4
- ? Please select the solution you want to create: Web App
5
- ? Development Language: TS
6
- ? Package Manager: pnpm
4
+ ? Please select the type of project you want to create: Web App
5
+ ? Please select the programming language: TS
6
+ ? Please select the package manager: pnpm
7
7
  ```
8
8
 
9
9
  After create the project, Modern.js automatically installs dependency and creates a git repository.
@@ -1,7 +1,7 @@
1
1
  ```bash
2
2
  $ npx @modern-js/create@latest myapp
3
- ? Please select the solution you want to create: Web App
4
- ? Development Language: TS
5
- ? Package Manager: pnpm
6
- ? Bundler: Rspack
3
+ ? Please select the type of project you want to create: Web App
4
+ ? Please select the programming language: TS
5
+ ? Please select the package manager: pnpm
6
+ ? Please select the bundler: Rspack
7
7
  ```
@@ -9,8 +9,8 @@ Modern.js also provides a runtime Polyfill solution based on browser [UA](https:
9
9
  exec `pnpm run new` to enable this features:
10
10
 
11
11
  ```bash
12
- ? Action Enable features
13
- ? Enable features Enable UA-based Polyfill Feature
12
+ ? Please select the operation you want: Enable features
13
+ ? Please select the feature name: Enable UA-based Polyfill Feature
14
14
  ```
15
15
 
16
16
  After executing the command, register the Polyfill plugin in `modern.config.ts`:
@@ -22,8 +22,8 @@ When using Rspack as the bundler, SWC will be used for transpiling and compressi
22
22
  First, you need to execute `pnpm run new` to enable the SWC compile:
23
23
 
24
24
  ```bash
25
- ? Action: Enable features
26
- ? Enable features: Enable SWC Compile
25
+ ? Please select the operation you want: Enable features
26
+ ? Please select the feature name: Enable SWC Compile
27
27
  ```
28
28
 
29
29
  After the installation, please register the SWC plugin in the `modern.config.ts` file, then the SWC compilation and compression will be enabled.
@@ -6,7 +6,7 @@ title: Frameworks
6
6
 
7
7
  Modern.js's BFF supports different runtime frameworks, currently Modern.js's BFF supports two runtime frameworks[Express.js](https://expressjs.com/) 和 [Koa.js](https://koajs.com/).
8
8
 
9
- ## Function Writing
9
+ ## Function Mode
10
10
 
11
11
  Under the function writing, only the middleware writing method of various runtime frameworks is different, and other implementations are basically the same. Take Express as an example to introduce how to write a middleware by hand in the `api/_ app.ts` and add permission verification:
12
12
 
@@ -96,7 +96,7 @@ Refresh the page and you can see that `/api/hello` was accessed successfully:
96
96
 
97
97
  The above code simulates the way to add middleware to the `/api/_app.ts` to achieve an easy login function. Also, other functions can be implemented in this hook file to extend BFF Server.
98
98
 
99
- ## Framework Writing
99
+ ## Framework Mode
100
100
 
101
101
  Under the framework writing, Modern.js does not collect middleware in the `api/_app.ts`, and the running process is controlled by the plugin itself.
102
102
 
@@ -51,10 +51,10 @@ Execute `pnpm run dev`, then open `http://localhost:8080/` to see that the page
51
51
 
52
52
  In Modern.js, the BFF function routing system is implemented based on the file system, and it is also a conventional routing system.
53
53
 
54
- In **Function Writing**, All files under `api/` will map to an interface. In **Framework Writing**, All files under `api/lambda` will map to an interface
54
+ In **Function Mode**, All files under `api/` will map to an interface. In **Framework Mode**, All files under `api/lambda` will map to an interface
55
55
 
56
56
  :::note
57
- Function Writing & Framework Writing will introduce soon.
57
+ Function Mode & Framework Mode will introduce soon.
58
58
 
59
59
  :::
60
60
 
@@ -69,14 +69,14 @@ Files named `index.[jt]s` are mapped to the previous directory.
69
69
  - `api/index.ts` -> `{prefix}/`
70
70
  - `api/user/index.ts` -> `{prefix}/user`
71
71
 
72
- ### Multi-layer Route
72
+ ### Multi-layer Routing
73
73
 
74
74
  Supports parsing nested files, if you create a nested folder structure, the files will still automatically parse routes in the same way.
75
75
 
76
76
  - `api/hello.ts` -> `{prefix}/hello`
77
77
  - `api/user/list.ts` -> `{prefix}/user/list`
78
78
 
79
- ### Dynamic Route
79
+ ### Dynamic Routing
80
80
 
81
81
  Create folders or files named with `[xxx]` to support dynamic named routing parameters.
82
82
 
@@ -1,19 +1,19 @@
1
1
  ---
2
2
  sidebar_position: 2
3
- title: Writing Type
3
+ title: BFF Type
4
4
  ---
5
- # Writing Type
5
+ # BFF Type
6
6
 
7
7
  Runtime framework support is also an important part of **BFF**. Modern.js supports extending BFF's runtime framework through plugins, and provides a series of built-in plugins, developers can directly use the conventions and ecology of the framework.
8
8
 
9
- The plugin is compatible with most of the specifications of these frameworks, and each framework needs to provide two types of ways to extend the writing of BFF functions, namely **Function Writing** and **Framework Writing**.
9
+ The plugin is compatible with most of the specifications of these frameworks, and each framework needs to provide two types of ways to extend the writing of BFF functions, namely **Function Mode** and **Framework Mode**.
10
10
 
11
11
  :::note
12
12
  Whether the current `api/` directory structure is written as a framework is determined by the corresponding plugin, Modern.js don't care.
13
13
 
14
14
  :::
15
15
 
16
- ## Function Writing
16
+ ## Function Mode
17
17
 
18
18
  When the plugin considers that it is currently written as a function, it must support writing middleware in the `api/_ app.ts` to extend the BFF function.
19
19
 
@@ -32,7 +32,7 @@ The writing of middleware for different plugins is not the same, see [Runtime Fr
32
32
 
33
33
  :::
34
34
 
35
- ## Framework Writing
35
+ ## Framework Mode
36
36
 
37
37
  Framework writing is a way of using frame structure to extend BFF functions. Compared with function writing, although frame writing can use more frame structure and make the entire BFF Server clearer in complex scenarios, it is also more complex and requires more attention to the content at the framework level.
38
38
 
@@ -36,8 +36,8 @@ You can enable Rspack build by running `pnpm run new`:
36
36
 
37
37
  ```bash
38
38
  $ pnpm run new
39
- ? Action: Enable features
40
- ? Enable features: Enable Rspack Build
39
+ ? Please select the operation you want: Enable features
40
+ ? Please select the feature name: Enable Rspack Build
41
41
  ```
42
42
 
43
43
  After executing the command, enable the Rspack build in `modern.config.ts`:
@@ -9,8 +9,8 @@ Static Site Generation is a solution for rendering complete static web pages at
9
9
  First need to execute `pnpm run new` to enable the SSG features:
10
10
 
11
11
  ```bash
12
- ? Action Enable features
13
- ? Enable features Enable SSG
12
+ ? Please select the operation you want: Enable features
13
+ ? Please select the feature name: Enable SSG
14
14
  ```
15
15
 
16
16
  After execute script, register SSG plugin in `modern.config.ts`:
@@ -9,8 +9,8 @@ Modern.js integrates the testing capabilities of [Jest](https://jestjs.io/) by d
9
9
  First need to execute `pnpm run new` enable [unit test/integration test] features:
10
10
 
11
11
  ```
12
- ? Action: Enable features
13
- ? Enable features: Enable Unit Test / Integration Test
12
+ ? Please select the operation you want: Enable features
13
+ ? Please select the feature name: Enable Unit Test / Integration Test
14
14
  ```
15
15
 
16
16
  After executing the above command, the `"test": "modern test"` command will be automatically generated in package.json.
@@ -27,8 +27,8 @@ Because the full web server cannot be controlled this way, and the extension log
27
27
  You can execute the'pnpm run new 'command in the project root directory to enable the "Custom Web Serve" function:
28
28
 
29
29
  ```bash
30
- ? Action Create project element
31
- ? New "Custom Web Server" source code directory
30
+ ? Please select the operation you want: Create Element
31
+ ? Please select the type of element to create: New "Custom Web Server" source code directory
32
32
  ```
33
33
 
34
34
  After executing the command, register the `@modern-js/plugin-server` plugin in `modern.config.ts`:
@@ -66,8 +66,8 @@ If you need to use other CSS-in-JS libraries such as [styled-jsx](https://www.np
66
66
  Follow the steps below to make a selection:
67
67
 
68
68
  ```bash
69
- ? Action: Enable features
70
- ? Enable features: Enable Tailwind CSS
69
+ ? Please select the operation you want: Enable features
70
+ ? Please select the feature name: Enable Tailwind CSS
71
71
  ```
72
72
 
73
73
  Register the Tailwind plugin in `modern.config.ts`:
@@ -182,7 +182,7 @@ Routes generated from file directories named with `[$]` will be treated as dynam
182
182
 
183
183
  The `routes/user/[id$]/page.tsx` file will be converted to the `/user/:id?` route. All routes under `/user` will match this route, and the `id` parameter is optional. This route is usually used to distinguish between **creation** and **editing**.
184
184
 
185
- In the component, you can use [useParams](/apis/app/runtime/router/router#useparams) to obtain the corresponding named parameter.
185
+ In the component, you can use [useParams](/apis/app/runtime/router/router#useparams) to get the corresponding named parameter.
186
186
 
187
187
  In the loader, params will be passed as the input parameter of the [loader function](/guides/basic-features/data-fetch#loader-function), and you can get the parameter value through `params.xxx`.
188
188
 
@@ -191,7 +191,7 @@ In the loader, params will be passed as the input parameter of the [loader funct
191
191
  If you create a `$.tsx` file under the routes directory, it will be treated as the catch-all routing component. When there is no matching route, this component will be rendered.
192
192
 
193
193
  :::note
194
- `$.tsx` can be considered as a special `page` route component. When there is a `layout` component in the current directory, `$.tsx` will be rendered as a child component of `layout`.
194
+ `$.tsx` can be considered as a special `page` route component. When there is a `layout.tsx` file in the current directory, `$.tsx` will be rendered as a child component of `layout`.
195
195
  :::
196
196
 
197
197
  For example, the following directory structure:
@@ -215,7 +215,7 @@ params['*']; // => 'aaa/bbb'
215
215
 
216
216
  ### No-path Layout
217
217
 
218
- When the directory name starts with `__`, the corresponding directory name will not be converted to an actual route path. For example, the following file directory:
218
+ When the directory name starts with `__`, the directory name will not be converted to an actual route path. For example, the following file directory:
219
219
 
220
220
  ```bash
221
221
  .
@@ -449,7 +449,7 @@ However, this also brings a problem: if the chunk corresponding to the route has
449
449
 
450
450
  In this case, you can define a `Loading` component to display a custom `Loading` component before the static resources are loaded.
451
451
 
452
- To further improve the user experience and reduce loading time, Modern.js supports defining the `prefetch` attribute on the Link component to preload static resources and data. The `prefetch` attribute has three optional values:
452
+ To further improve the user experience and reduce loading time, Modern.js supports defining the `prefetch` attribute on the Link component to preload static resources and data.
453
453
 
454
454
  ```tsx
455
455
  <Link prefetch="intent" to="page">
@@ -461,6 +461,8 @@ To further improve the user experience and reduce loading time, Modern.js suppor
461
461
 
462
462
  :::
463
463
 
464
+ The `prefetch` attribute has three optional values:
465
+
464
466
  - `none`: default value, no prefetching, no additional behavior.
465
467
  - `intent`: This is the value we recommend for most scenarios. When you hover over the Link, the corresponding chunk and data defined in the data loader will be loaded automatically. When you move the mouse away, the loading will be cancelled automatically. In our tests, even fast clicks can reduce loading time by about 200ms.
466
468
  - `render`: The corresponding chunk and data defined in the Data Loader will be loaded when the Link component is rendered.
@@ -504,8 +506,6 @@ export default () => {
504
506
  Modern.js provides a series of optimizations for resource loading and rendering for conventional routing by default, and provides out-of-the-box SSR capabilities. When using self-controlled routing, developers need to encapsulate these capabilities themselves. It is recommended to use conventional routing.
505
507
  :::
506
508
 
507
- When using self-controlled routing, if the developer turns off the [`runtime.router`](/configure/app/runtime/router) configuration and uses `react-router-dom` directly, they also need to wrap it according to the React Router documentation.
508
-
509
509
  ## Other
510
510
 
511
511
  By default, Modern.js will enable the built-in routing scheme, which is React Router.
@@ -518,7 +518,9 @@ export default defineConfig({
518
518
  });
519
519
  ```
520
520
 
521
- Modern.js exposes the API of React Router from the `@modern-js/runtime/router` namespace for developers to use, ensuring that developers and Modern.js use the same code. In addition, in this case, the React Router code will be bundled into the JS output. If the project already has its own routing scheme or does not need to use client-side routing, this feature can be turned off.
521
+ As mentioned above, when the [`runtime.router`](/configure/app/runtime/router) configuration is enabled, Modern.js will export the API of React Router from the `@modern-js/runtime/router` namespace for developers to use, ensuring that developers and Modern.js are using the same code, and automatically wrapping the `Provider` component according to the router configuration. In addition, in this case, the code of React Router will be packed into the JS output.
522
+
523
+ If the project already has its own routing plan or does not need to use client-side routing, this feature can be disabled.
522
524
 
523
525
  ```js
524
526
  export default defineConfig({
@@ -527,3 +529,5 @@ export default defineConfig({
527
529
  },
528
530
  });
529
531
  ```
532
+
533
+ As mentioned above, if the [`runtime.router`](/configure/app/runtime/router) configuration is disabled and `react-router-dom` is used directly for project routing management, the `Provider` needs to be wrapped according to the React Router documentation.
@@ -33,9 +33,9 @@ The project initialized by Modern.js is single-entry (SPA), and the project stru
33
33
  Modern.js can easily switch from single entry to multiple entry. You can execute `pnpm run new` under the project to create entry through generator:
34
34
 
35
35
  ```bash
36
- ? Action: Create project element
37
- ? Create project element: New "entry"
38
- ? Entry name: new-entry
36
+ ? Please select the operation you want: Create Element
37
+ ? Please select the type of element to create: New "entry"
38
+ ? Please fill in the entry name: new-entry
39
39
  ```
40
40
 
41
41
  After execution, Modern.js will automatically generate a new entry directory, and you can see that the `src/` directory has the following structure: