@modern-js/main-doc 2.21.0 → 2.22.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +24 -0
- package/docs/en/apis/app/commands.mdx +5 -5
- package/docs/en/apis/app/hooks/api/api.mdx +80 -0
- package/docs/en/apis/app/hooks/api/app.mdx +12 -0
- package/docs/en/apis/app/hooks/api/lambda.mdx +57 -0
- package/docs/en/apis/app/hooks/api/test.mdx +1 -1
- package/docs/en/apis/app/hooks/config/html.mdx +2 -2
- package/docs/en/apis/app/hooks/config/icon.mdx +19 -19
- package/docs/en/apis/app/hooks/config/mock.mdx +1 -1
- package/docs/en/apis/app/hooks/config/public.mdx +10 -10
- package/docs/en/apis/app/hooks/config/storybook.mdx +3 -3
- package/docs/en/apis/app/hooks/config/upload.mdx +13 -13
- package/docs/en/apis/app/hooks/modern-config.mdx +4 -4
- package/docs/en/apis/app/hooks/server/index_.mdx +2 -9
- package/docs/en/apis/app/hooks/server/test.mdx +5 -2
- package/docs/en/apis/app/hooks/shared.mdx +1 -1
- package/docs/en/apis/app/hooks/src/app.mdx +17 -27
- package/docs/en/apis/app/hooks/src/index_.mdx +6 -6
- package/docs/en/apis/app/hooks/src/pages.mdx +41 -37
- package/docs/en/apis/app/hooks/src/routes.mdx +16 -36
- package/docs/en/apis/app/hooks/src/server.mdx +1 -1
- package/docs/en/apis/app/hooks/src/stories.mdx +6 -3
- package/docs/en/apis/app/hooks/src/test.mdx +4 -3
- package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +5 -1
- package/docs/en/apis/app/runtime/web-server/hook.mdx +2 -2
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +2 -2
- package/docs/en/components/global-proxy.mdx +7 -7
- package/docs/en/components/init-app.mdx +3 -3
- package/docs/en/components/init-rspack-app.mdx +4 -4
- package/docs/en/components/language-config.mdx +9 -0
- package/docs/en/components/package-manager.mdx +11 -0
- package/docs/en/components/ua-polyfill.mdx +2 -2
- package/docs/en/configure/app/source/config-dir.mdx +1 -1
- package/docs/en/configure/app/source/design-system.mdx +67 -67
- package/docs/en/configure/app/source/disable-default-entries.mdx +6 -5
- package/docs/en/configure/app/source/disable-entry-dirs.mdx +5 -5
- package/docs/en/configure/app/source/enable-async-entry.mdx +9 -9
- package/docs/en/configure/app/source/entries-dir.mdx +3 -3
- package/docs/en/configure/app/source/entries.mdx +21 -19
- package/docs/en/configure/app/tools/swc.mdx +2 -2
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -2
- package/docs/en/guides/advanced-features/bff/function.mdx +4 -4
- package/docs/en/guides/advanced-features/bff/type.mdx +5 -5
- package/docs/en/guides/advanced-features/rspack-start.mdx +6 -6
- package/docs/en/guides/advanced-features/ssg.mdx +2 -2
- package/docs/en/guides/advanced-features/testing.mdx +2 -2
- package/docs/en/guides/advanced-features/web-server.mdx +2 -2
- package/docs/en/guides/basic-features/css.mdx +2 -2
- package/docs/en/guides/basic-features/mock.mdx +1 -1
- package/docs/en/guides/basic-features/proxy.mdx +4 -5
- package/docs/en/guides/basic-features/routes.mdx +11 -7
- package/docs/en/guides/concept/entries.mdx +3 -3
- package/docs/en/guides/topic-detail/generator/create/_category_.json +4 -0
- package/docs/en/guides/topic-detail/generator/create/config.mdx +75 -0
- package/docs/en/guides/topic-detail/generator/create/option.md +151 -0
- package/docs/en/guides/topic-detail/generator/create/use.mdx +66 -0
- package/docs/en/guides/topic-detail/generator/new/_category_.json +4 -0
- package/docs/en/guides/topic-detail/generator/new/config.md +155 -0
- package/docs/en/guides/topic-detail/generator/new/option.md +67 -0
- package/docs/en/guides/topic-detail/generator/new/use.md +95 -0
- package/docs/en/guides/topic-detail/generator/plugin/_category_.json +2 -2
- package/docs/en/guides/topic-detail/generator/plugin/api/_category_.json +1 -1
- package/docs/en/guides/topic-detail/generator/plugin/api/afterForged.md +49 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/context.md +184 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/input.md +124 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/onForged.md +310 -0
- package/docs/en/guides/topic-detail/generator/plugin/category.md +88 -0
- package/docs/en/guides/topic-detail/generator/plugin/context.md +104 -0
- package/docs/en/guides/topic-detail/generator/plugin/structure.md +106 -0
- package/docs/en/guides/topic-detail/generator/plugin/use.md +33 -0
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +8 -8
- package/docs/en/tutorials/first-app/c03-css.mdx +2 -2
- package/docs/en/tutorials/first-app/c08-entries.mdx +3 -3
- package/docs/zh/apis/app/commands.mdx +3 -3
- package/docs/zh/apis/app/hooks/api/{functions/api.mdx → api.mdx} +4 -4
- package/docs/zh/apis/app/hooks/api/app.mdx +12 -0
- package/docs/zh/apis/app/hooks/api/{framework/lambda.mdx → lambda.mdx} +5 -5
- package/docs/zh/apis/app/hooks/api/test.mdx +3 -3
- package/docs/zh/apis/app/hooks/config/icon.mdx +15 -15
- package/docs/zh/apis/app/hooks/config/mock.mdx +1 -1
- package/docs/zh/apis/app/hooks/config/public.mdx +3 -3
- package/docs/zh/apis/app/hooks/config/upload.mdx +1 -1
- package/docs/zh/apis/app/hooks/modern-config.mdx +3 -3
- package/docs/zh/apis/app/hooks/server/index_.mdx +1 -6
- package/docs/zh/apis/app/hooks/shared.mdx +1 -1
- package/docs/zh/apis/app/hooks/src/app.mdx +15 -25
- package/docs/zh/apis/app/hooks/src/index_.mdx +6 -6
- package/docs/zh/apis/app/hooks/src/pages.mdx +7 -3
- package/docs/zh/apis/app/hooks/src/routes.mdx +4 -4
- package/docs/zh/apis/app/hooks/src/stories.mdx +1 -1
- package/docs/zh/apis/app/runtime/core/use-runtime-context.mdx +5 -1
- package/docs/zh/components/language-config.mdx +9 -0
- package/docs/zh/components/package-manager.mdx +11 -0
- package/docs/zh/components/ua-polyfill.mdx +1 -1
- package/docs/zh/configure/app/source/design-system.mdx +3 -4
- package/docs/zh/configure/app/source/enable-async-entry.mdx +2 -5
- package/docs/zh/configure/app/source/entries.mdx +2 -2
- package/docs/zh/configure/app/tools/swc.mdx +2 -2
- package/docs/zh/guides/advanced-features/rspack-start.mdx +6 -6
- package/docs/zh/guides/advanced-features/ssg.mdx +1 -1
- package/docs/zh/guides/advanced-features/testing.mdx +2 -2
- package/docs/zh/guides/advanced-features/web-server.mdx +1 -1
- package/docs/zh/guides/basic-features/css.mdx +1 -1
- package/docs/zh/guides/basic-features/mock.mdx +1 -1
- package/docs/zh/guides/basic-features/routes.mdx +7 -4
- package/docs/zh/guides/concept/entries.mdx +3 -3
- package/docs/zh/guides/topic-detail/generator/create/_category_.json +4 -0
- package/docs/zh/guides/topic-detail/generator/create/config.mdx +76 -0
- package/docs/zh/guides/topic-detail/generator/create/option.md +151 -0
- package/docs/zh/guides/topic-detail/generator/create/use.mdx +66 -0
- package/docs/zh/guides/topic-detail/generator/new/_category_.json +4 -0
- package/docs/zh/guides/topic-detail/generator/new/config.md +153 -0
- package/docs/zh/guides/topic-detail/generator/new/option.md +67 -0
- package/docs/zh/guides/topic-detail/generator/new/use.md +94 -0
- package/docs/zh/guides/topic-detail/generator/plugin/_category_.json +2 -2
- package/docs/zh/guides/topic-detail/generator/plugin/api/_category_.json +1 -1
- package/docs/zh/guides/topic-detail/generator/plugin/api/afterForged.md +50 -0
- package/docs/zh/guides/topic-detail/generator/plugin/api/context.md +184 -0
- package/docs/zh/guides/topic-detail/generator/plugin/api/input.md +124 -0
- package/docs/zh/guides/topic-detail/generator/plugin/api/onForged.md +310 -0
- package/docs/zh/guides/topic-detail/generator/plugin/category.md +93 -0
- package/docs/zh/guides/topic-detail/generator/plugin/context.md +105 -0
- package/docs/zh/guides/topic-detail/generator/plugin/structure.md +106 -0
- package/docs/zh/guides/topic-detail/generator/plugin/use.md +33 -0
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +4 -4
- package/docs/zh/guides/topic-detail/model/test-model.mdx +1 -1
- package/docs/zh/tutorials/first-app/c03-css.mdx +1 -1
- package/docs/zh/tutorials/first-app/c08-entries.mdx +1 -1
- package/modern.config.ts +2 -1
- package/package.json +5 -5
- package/docs/en/apis/app/hooks/api/framework/_category_.json +0 -4
- package/docs/en/apis/app/hooks/api/framework/lambda.mdx +0 -57
- package/docs/en/apis/app/hooks/api/functions/_category_.json +0 -4
- package/docs/en/apis/app/hooks/api/functions/api.mdx +0 -81
- package/docs/en/apis/app/hooks/api/functions/app.mdx +0 -12
- package/docs/en/apis/app/hooks/api/functions/common.mdx +0 -9
- package/docs/en/guides/topic-detail/generator/codesmith/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/codesmith/api/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/codesmith/api/app.mdx +0 -152
- package/docs/en/guides/topic-detail/generator/codesmith/api/ejs.mdx +0 -56
- package/docs/en/guides/topic-detail/generator/codesmith/api/fs.mdx +0 -54
- package/docs/en/guides/topic-detail/generator/codesmith/api/git.mdx +0 -50
- package/docs/en/guides/topic-detail/generator/codesmith/api/handlebars.mdx +0 -57
- package/docs/en/guides/topic-detail/generator/codesmith/api/json.mdx +0 -56
- package/docs/en/guides/topic-detail/generator/codesmith/api/npm.mdx +0 -48
- package/docs/en/guides/topic-detail/generator/codesmith/develop.mdx +0 -53
- package/docs/en/guides/topic-detail/generator/codesmith/introduce.mdx +0 -47
- package/docs/en/guides/topic-detail/generator/codesmith/run-in-js.mdx +0 -47
- package/docs/en/guides/topic-detail/generator/codesmith/structure.mdx +0 -89
- package/docs/en/guides/topic-detail/generator/config/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/config/app.mdx +0 -82
- package/docs/en/guides/topic-detail/generator/config/common.mdx +0 -100
- package/docs/en/guides/topic-detail/generator/config/module.mdx +0 -42
- package/docs/en/guides/topic-detail/generator/config/monorepo.mdx +0 -28
- package/docs/en/guides/topic-detail/generator/plugin/abstract.mdx +0 -23
- package/docs/en/guides/topic-detail/generator/plugin/api/file/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addFile.mdx +0 -52
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addHelper.mdx +0 -26
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addManyFile.mdx +0 -58
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addPartial.mdx +0 -26
- package/docs/en/guides/topic-detail/generator/plugin/api/file/introduce.mdx +0 -39
- package/docs/en/guides/topic-detail/generator/plugin/api/file/rmDir.mdx +0 -24
- package/docs/en/guides/topic-detail/generator/plugin/api/file/rmFile.mdx +0 -24
- package/docs/en/guides/topic-detail/generator/plugin/api/file/updateJSONFile.mdx +0 -54
- package/docs/en/guides/topic-detail/generator/plugin/api/file/updateModernConfig.mdx +0 -27
- package/docs/en/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.mdx +0 -33
- package/docs/en/guides/topic-detail/generator/plugin/api/git/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/git/gitAddAndCommit.mdx +0 -20
- package/docs/en/guides/topic-detail/generator/plugin/api/git/initGitRepo.mdx +0 -16
- package/docs/en/guides/topic-detail/generator/plugin/api/git/isInGitRepo.mdx +0 -16
- package/docs/en/guides/topic-detail/generator/plugin/api/hook/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/hook/afterForged.mdx +0 -35
- package/docs/en/guides/topic-detail/generator/plugin/api/hook/onForged.mdx +0 -35
- package/docs/en/guides/topic-detail/generator/plugin/api/info/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/info/isFileExit.mdx +0 -22
- package/docs/en/guides/topic-detail/generator/plugin/api/info/locale.mdx +0 -17
- package/docs/en/guides/topic-detail/generator/plugin/api/info/readDir.mdx +0 -22
- package/docs/en/guides/topic-detail/generator/plugin/api/input/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/input/addInputAfter.mdx +0 -55
- package/docs/en/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +0 -55
- package/docs/en/guides/topic-detail/generator/plugin/api/input/setInput.mdx +0 -43
- package/docs/en/guides/topic-detail/generator/plugin/api/input/setInputValue.mdx +0 -31
- package/docs/en/guides/topic-detail/generator/plugin/api/input/type.mdx +0 -65
- package/docs/en/guides/topic-detail/generator/plugin/api/introduce.mdx +0 -90
- package/docs/en/guides/topic-detail/generator/plugin/api/new/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/new/createElement.mdx +0 -33
- package/docs/en/guides/topic-detail/generator/plugin/api/new/createSubProject.mdx +0 -35
- package/docs/en/guides/topic-detail/generator/plugin/api/new/enableFunc.mdx +0 -44
- package/docs/en/guides/topic-detail/generator/plugin/api/new/introduce.mdx +0 -15
- package/docs/en/guides/topic-detail/generator/plugin/api/npm/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/npm/install.mdx +0 -18
- package/docs/en/guides/topic-detail/generator/plugin/develop.mdx +0 -125
- package/docs/en/guides/topic-detail/generator/plugin/use.mdx +0 -61
- package/docs/en/guides/topic-detail/generator/project.mdx +0 -118
- package/docs/zh/apis/app/hooks/api/framework/_category_.json +0 -4
- package/docs/zh/apis/app/hooks/api/functions/_category_.json +0 -4
- package/docs/zh/apis/app/hooks/api/functions/app.mdx +0 -12
- package/docs/zh/apis/app/hooks/api/functions/common.mdx +0 -9
- package/docs/zh/guides/topic-detail/generator/codesmith/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/codesmith/api/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/codesmith/api/app.mdx +0 -152
- package/docs/zh/guides/topic-detail/generator/codesmith/api/ejs.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/codesmith/api/fs.mdx +0 -54
- package/docs/zh/guides/topic-detail/generator/codesmith/api/git.mdx +0 -49
- package/docs/zh/guides/topic-detail/generator/codesmith/api/handlebars.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/codesmith/api/json.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/codesmith/api/npm.mdx +0 -47
- package/docs/zh/guides/topic-detail/generator/codesmith/develop.mdx +0 -53
- package/docs/zh/guides/topic-detail/generator/codesmith/introduce.mdx +0 -59
- package/docs/zh/guides/topic-detail/generator/codesmith/run-in-js.mdx +0 -47
- package/docs/zh/guides/topic-detail/generator/codesmith/structure.mdx +0 -89
- package/docs/zh/guides/topic-detail/generator/config/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/config/app.mdx +0 -82
- package/docs/zh/guides/topic-detail/generator/config/common.mdx +0 -100
- package/docs/zh/guides/topic-detail/generator/config/module.mdx +0 -42
- package/docs/zh/guides/topic-detail/generator/config/monorepo.mdx +0 -28
- package/docs/zh/guides/topic-detail/generator/plugin/abstract.mdx +0 -23
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addFile.mdx +0 -52
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addHelper.mdx +0 -26
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addManyFile.mdx +0 -55
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addPartial.mdx +0 -26
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/introduce.mdx +0 -39
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/rmDir.mdx +0 -24
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/rmFile.mdx +0 -24
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateJSONFile.mdx +0 -54
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateModernConfig.mdx +0 -27
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.mdx +0 -33
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/gitAddAndCommit.mdx +0 -20
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/initGitRepo.mdx +0 -16
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/isInGitRepo.mdx +0 -16
- package/docs/zh/guides/topic-detail/generator/plugin/api/hook/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/hook/afterForged.mdx +0 -35
- package/docs/zh/guides/topic-detail/generator/plugin/api/hook/onForged.mdx +0 -35
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/isFileExit.mdx +0 -22
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/locale.mdx +0 -17
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/readDir.mdx +0 -22
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/addInputAfter.mdx +0 -57
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/setInput.mdx +0 -43
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/setInputValue.mdx +0 -29
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/type.mdx +0 -65
- package/docs/zh/guides/topic-detail/generator/plugin/api/introduce.mdx +0 -92
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/createElement.mdx +0 -33
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/createSubProject.mdx +0 -35
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/enableFunc.mdx +0 -44
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/introduce.mdx +0 -15
- package/docs/zh/guides/topic-detail/generator/plugin/api/npm/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/npm/install.mdx +0 -16
- package/docs/zh/guides/topic-detail/generator/plugin/develop.mdx +0 -125
- package/docs/zh/guides/topic-detail/generator/plugin/use.mdx +0 -61
- package/docs/zh/guides/topic-detail/generator/project.mdx +0 -118
@@ -4,11 +4,15 @@ sidebar_position: 3
|
|
4
4
|
---
|
5
5
|
# pages/
|
6
6
|
|
7
|
-
|
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
|
-
|
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
|
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
|
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
|
37
|
-
-
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
79
|
+
On the basis of dynamic routing, special routing suffixes `(*, ?, +)` can be added.
|
76
80
|
|
77
|
-
For example: `src/pages/users/[id]*.tsx`
|
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
|
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
|
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
|
-
-
|
111
|
-
-
|
112
|
-
-
|
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
|
-
-
|
117
|
-
-
|
118
|
-
-
|
119
|
-
-
|
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
|
129
|
+
When developing an application, there are scenarios where sub-routes under the same route share a layout.
|
126
130
|
|
127
|
-
For this
|
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
|
154
|
+
The `Component` parameter is the component corresponding to a specific accessed route, for example:
|
151
155
|
|
152
|
-
-
|
153
|
-
-
|
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,
|
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
|
-
|
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
|
-
|
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
|
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
|
7
|
+
The identifier for the entry point when the application uses [Conventional Routing](guides/basic-features/routes.html#conventional-routing).
|
8
8
|
|
9
|
-
|
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
|
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
|
-
##
|
23
|
+
## Basic Example
|
24
24
|
|
25
|
-
The directory
|
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
|
-
|
35
|
+
will generate two routes:
|
36
36
|
|
37
37
|
- `/`
|
38
38
|
- `/user`
|
39
39
|
|
40
|
-
## Dynamic
|
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
|
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
|
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
|
55
|
+
In the component, you can use [useParams](/apis/app/runtime/router/router#useparams) to obtain the corresponding named parameter.
|
56
56
|
|
57
|
-
|
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
|
-
##
|
59
|
+
## Layout Component
|
60
60
|
|
61
|
-
|
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
|
-
|
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]
|
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
|
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
|
-
|
7
|
+
Application project Storybook files.
|
8
8
|
|
9
|
-
|
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
|
-
|
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
|
-
|
8
|
+
Application project test files.
|
8
9
|
|
9
|
-
The
|
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
|
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
|
:::
|
@@ -28,6 +28,7 @@ type RuntimeContext = {
|
|
28
28
|
cookie: string;
|
29
29
|
};
|
30
30
|
store: ReduckStore;
|
31
|
+
router: RemixRouter;
|
31
32
|
};
|
32
33
|
|
33
34
|
function useRuntimeContext(): RuntimeContext;
|
@@ -41,7 +42,10 @@ function useRuntimeContext(): RuntimeContext;
|
|
41
42
|
- `query`: the query of the request.
|
42
43
|
- `headers`: the header info of the request.
|
43
44
|
- `cookie`: the cookie of the request.
|
44
|
-
- `store`: when the runtime.state is enabled, this value is the
|
45
|
+
- `store`: when the `runtime.state` is enabled, this value is the Reduck global `store`.
|
46
|
+
- `router`: When the `runtime.router` is enabled, this value exists.
|
47
|
+
- `location`: The current location reflected by the router. The same as [`useLocation`] the return value of (/apis/app/runtime/router/router.html#uselocation).
|
48
|
+
- `navigate`: Navigate to the given path. The same as the return value of [`useNavigate`](/apis/app/runtime/router/router.html#usenavigate).
|
45
49
|
|
46
50
|
## Example
|
47
51
|
|
@@ -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
|
-
?
|
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
|
-
?
|
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,14 +1,14 @@
|
|
1
|
-
Modern.js provides out-of-the-box global proxy plugin `@modern-js/plugin-proxy`, which is based on [whistle](https://github.com/avwo/whistle) and can be used to view and modify
|
1
|
+
Modern.js provides an out-of-the-box global proxy plugin `@modern-js/plugin-proxy`, which is based on [whistle](https://github.com/avwo/whistle) and can be used to view and modify the requests and responses of HTTP/HTTPS, as well as be used as an HTTP proxy server.
|
2
2
|
|
3
|
-
###
|
3
|
+
### Setting Proxy Rules
|
4
4
|
|
5
|
-
After
|
5
|
+
After installing the proxy plugin and configuring the rules, run `pnpm run dev`. Modern.js will automatically enable the proxy server when the development server is started.
|
6
6
|
|
7
7
|
Specific proxy rules can be set via the [`dev.proxy`](/configure/app/dev/proxy) or the `config/proxy.js` file.
|
8
8
|
|
9
|
-
###
|
9
|
+
### Proxy Dashboard
|
10
10
|
|
11
|
-
After
|
11
|
+
After installing the proxy plugin and configuring the proxy rules, run the `pnpm run dev` command:
|
12
12
|
|
13
13
|
```bash
|
14
14
|
App running at:
|
@@ -20,8 +20,8 @@ After exec `pnpm run dev` command:
|
|
20
20
|
✔ success Proxy Server start on localhost:8899
|
21
21
|
```
|
22
22
|
|
23
|
-
|
23
|
+
You can see that the proxy server has started successfully in the console.
|
24
24
|
|
25
|
-
|
25
|
+
Access `http://localhost:8899`, and you can set the rules through the dashboard.
|
26
26
|
|
27
27
|

|
@@ -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
|
5
|
-
?
|
6
|
-
?
|
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
|
4
|
-
?
|
5
|
-
?
|
6
|
-
?
|
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
|
-
?
|
13
|
-
?
|
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`:
|
@@ -9,7 +9,7 @@ sidebar_label: configDir
|
|
9
9
|
|
10
10
|
Modern.js supports placing some files in the `./config` folder to customize HTML templates, icons, static resources, etc. For details, please refer to [File Convention](/apis/app/hooks/config/html).
|
11
11
|
|
12
|
-
This option allows you to customize the directory of configuration files.
|
12
|
+
This option allows you to customize the directory of the configuration files.
|
13
13
|
|
14
14
|
For example, adjust the resource file directory to the `resources` directory:
|
15
15
|
|