@modern-js/main-doc 0.0.0-nightly-20240828170710 → 0.0.0-nightly-20240830170740
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/en/apis/app/runtime/core/use-loader.mdx +1 -1
- package/docs/en/components/ssr-monitor.mdx +3 -0
- package/docs/en/configure/app/output/ssg.mdx +52 -141
- package/docs/en/guides/advanced-features/_meta.json +0 -7
- package/docs/en/guides/basic-features/_meta.json +7 -1
- package/docs/en/guides/basic-features/data/data-fetch.mdx +134 -235
- package/docs/en/guides/basic-features/data/data-write.mdx +66 -77
- package/docs/en/guides/basic-features/render/_meta.json +1 -0
- package/docs/en/guides/basic-features/render/ssg.mdx +208 -0
- package/docs/en/guides/{advanced-features/ssr/cache.mdx → basic-features/render/ssr-cache.mdx} +38 -50
- package/docs/en/guides/basic-features/render/ssr.mdx +301 -0
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +230 -0
- package/docs/en/guides/basic-features/routes.mdx +275 -263
- package/docs/en/guides/concept/entries.mdx +9 -2
- package/docs/zh/apis/app/runtime/core/use-loader.mdx +1 -1
- package/docs/zh/components/ssr-monitor.mdx +3 -0
- package/docs/zh/configure/app/output/ssg.mdx +49 -139
- package/docs/zh/guides/advanced-features/_meta.json +0 -7
- package/docs/zh/guides/basic-features/_meta.json +7 -1
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +96 -211
- package/docs/zh/guides/basic-features/data/data-write.mdx +54 -55
- package/docs/zh/guides/basic-features/render/_meta.json +1 -0
- package/docs/zh/guides/basic-features/render/ssg.mdx +210 -0
- package/docs/zh/guides/{advanced-features/ssr/cache.mdx → basic-features/render/ssr-cache.mdx} +16 -26
- package/docs/zh/guides/basic-features/render/ssr.mdx +309 -0
- package/docs/zh/guides/{advanced-features/ssr/stream.mdx → basic-features/render/streaming-ssr.mdx} +22 -37
- package/docs/zh/guides/basic-features/routes.mdx +252 -237
- package/docs/zh/guides/concept/entries.mdx +6 -3
- package/package.json +6 -6
- package/docs/en/guides/advanced-features/ssg.mdx +0 -116
- package/docs/en/guides/advanced-features/ssr/_meta.json +0 -1
- package/docs/en/guides/advanced-features/ssr/index.mdx +0 -23
- package/docs/en/guides/advanced-features/ssr/stream.mdx +0 -248
- package/docs/en/guides/advanced-features/ssr/usage.mdx +0 -341
- package/docs/en/guides/advanced-features/ssr.mdx +0 -555
- package/docs/zh/guides/advanced-features/ssg.mdx +0 -116
- package/docs/zh/guides/advanced-features/ssr/_meta.json +0 -1
- package/docs/zh/guides/advanced-features/ssr/index.mdx +0 -23
- package/docs/zh/guides/advanced-features/ssr/usage.mdx +0 -329
@@ -116,6 +116,8 @@ For more information, please refer to [Conventional Routing](/guides/basic-featu
|
|
116
116
|
|
117
117
|
#### Self-controlled Routing
|
118
118
|
|
119
|
+
## Manual Routing
|
120
|
+
|
119
121
|
If there is an `App.[jt]sx?` file within the entry, we refer to this entry as a self-controlled route. For example:
|
120
122
|
|
121
123
|
```bash
|
@@ -124,7 +126,9 @@ If there is an `App.[jt]sx?` file within the entry, we refer to this entry as a
|
|
124
126
|
│ └── App.tsx
|
125
127
|
```
|
126
128
|
|
127
|
-
|
129
|
+
For entry points defined as `src/App.tsx`, Modern.js does not perform any additional routing operations. Developers can use the [React Router 6](https://reactrouter.com/en/main) API for development, define client-side routes or not to set any client-side routes.
|
130
|
+
|
131
|
+
for example, define client-side routes in application:
|
128
132
|
|
129
133
|
```tsx
|
130
134
|
import { BrowserRouter, Route, Routes } from '@modern-js/runtime/router';
|
@@ -141,7 +145,10 @@ export default () => {
|
|
141
145
|
};
|
142
146
|
```
|
143
147
|
|
144
|
-
|
148
|
+
:::note
|
149
|
+
We recommend that developers use conventional routing. Modern.js provides a series of optimizations in resource loading and rendering for conventional routing by default and offers built-in SSR capabilities. When using manual routing, these capabilities need to be encapsulated by developers themselves.
|
150
|
+
:::
|
151
|
+
|
145
152
|
|
146
153
|
#### Custom Entry
|
147
154
|
|
@@ -52,7 +52,7 @@ function useLoader(loaderFn: LoaderFn, options: Options): ReturnData;
|
|
52
52
|
- `initialData`:首次执行前的初始数据,对应返回值中的 `data` 字段。
|
53
53
|
- `skip`:当值为 `true` 时,函数不执行。
|
54
54
|
- `params`:当 `params` 序列化结果发生改变时,函数会重新执行。同时,`params` 也会作为函数的第二个参数被传入。
|
55
|
-
- `static`:当值为 `true` 时,`useLoader` 用于 [SSG](/guides/
|
55
|
+
- `static`:当值为 `true` 时,`useLoader` 用于 [SSG](/guides/basic-features/render/ssg) 编译阶段数据的获取。
|
56
56
|
|
57
57
|
### 返回值
|
58
58
|
|
@@ -4,44 +4,22 @@ title: ssg
|
|
4
4
|
|
5
5
|
# output.ssg
|
6
6
|
|
7
|
-
- **类型:** `boolean` | `object`
|
7
|
+
- **类型:** `boolean` | `object`
|
8
8
|
- **默认值:** `undefined`
|
9
9
|
|
10
|
-
|
10
|
+
开启应用 SSG 功能的配置
|
11
11
|
|
12
|
-
:::
|
13
|
-
此配置需要在开启 SSG 功能情况下才会生效。请阅读 [静态站点生成](/guides/
|
12
|
+
:::tip 开启 SSG 功能
|
13
|
+
此配置需要在开启 SSG 功能情况下才会生效。请阅读 [静态站点生成](/guides/basic-features/render/ssg) 文档了解如何开启 SSG 功能及使用场景。
|
14
14
|
:::
|
15
15
|
|
16
|
-
:::info
|
17
|
-
|
18
|
-
|
16
|
+
:::info 前置阅读
|
17
|
+
SSG 功能使用与路由关联性较大,建议使用前先了解[路由方案](/guides/basic-features/routes)。
|
19
18
|
:::
|
20
19
|
|
21
|
-
##
|
22
|
-
|
23
|
-
### 单入口
|
24
|
-
|
25
|
-
当该配置设置为 `true` 时,将会默认开启所有入口的 SSG 功能。
|
26
|
-
|
27
|
-
对**自控式路由**而言,将会渲染入口的根路由。对**约定式路由**而言,将会渲染入口中每一条路由。
|
28
|
-
|
29
|
-
例如 `src/` 目录下有以下满足**约定式路由**的文件结构:
|
30
|
-
|
31
|
-
```bash
|
32
|
-
.
|
33
|
-
├── src
|
34
|
-
│ └── routes
|
35
|
-
│ ├── layout.tsx
|
36
|
-
│ ├── page.tsx
|
37
|
-
│ └── user
|
38
|
-
│ ├── layout.tsx
|
39
|
-
│ ├── page.tsx
|
40
|
-
│ └── profile
|
41
|
-
│ └── page.tsx
|
42
|
-
```
|
20
|
+
## Boolean 类型
|
43
21
|
|
44
|
-
|
22
|
+
当该配置设置为 `true` 时,将会默认开启所有入口的 SSG 功能。对**自控式路由**而言,将会渲染入口的根路由。对**约定式路由**而言,将会渲染入口中每一条路由。
|
45
23
|
|
46
24
|
```js
|
47
25
|
export default defineConfig({
|
@@ -51,39 +29,20 @@ export default defineConfig({
|
|
51
29
|
});
|
52
30
|
```
|
53
31
|
|
54
|
-
执行 `pnpm build` 构建应用后。`dist/` 目录将会生成三张 HTML 分别对应三条路由(不开启 SSG 时只有一张 HTML),并且所有 HTML 都已经渲染。
|
55
|
-
|
56
|
-
而例如下面的**自控式路由**:
|
57
|
-
|
58
|
-
import SelfRouteExample from "@site-docs/components/self-route-example";
|
59
|
-
|
60
|
-
<SelfRouteExample />
|
61
|
-
|
62
|
-
同样使用上面的配置,在执行 `pnpm run build` 后,只有入口路由 `/` 会生成渲染后的 HTML。
|
63
|
-
|
64
|
-
### 多入口
|
65
|
-
|
66
32
|
`output.ssg` 也可以按照入口配置,配置生效的规则同样由入口路由方式决定。
|
67
33
|
|
68
|
-
|
34
|
+
例如以下目录结构,分别存在约定式路由入口 `entryA` 和自控式路由入口 `entryB`:
|
69
35
|
|
70
36
|
```bash
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
│
|
75
|
-
|
76
|
-
|
77
|
-
│ │ └── user
|
78
|
-
│ │ ├── layout.tsx
|
79
|
-
│ │ ├── page.tsx
|
80
|
-
│ │ └── profile
|
81
|
-
│ │ └── page.tsx
|
82
|
-
│ └── entryB
|
83
|
-
│ └── App.tsx
|
37
|
+
.
|
38
|
+
└── src
|
39
|
+
├── entryA
|
40
|
+
│ └── routes
|
41
|
+
└── entryB
|
42
|
+
└── App.tsx
|
84
43
|
```
|
85
44
|
|
86
|
-
|
45
|
+
你可以指定 `entryA` 和 `entryB` 的不同 SSG 配置:
|
87
46
|
|
88
47
|
```js
|
89
48
|
export default defineConfig({
|
@@ -96,107 +55,58 @@ export default defineConfig({
|
|
96
55
|
});
|
97
56
|
```
|
98
57
|
|
99
|
-
### 配置路由
|
100
|
-
|
101
|
-
上述内容中提到,**自控式路由**默认只会开启入口路由的 SSG 配置。
|
102
|
-
|
103
|
-
可以在 `output.ssg` 中设置具体的路由,告知 Modern.js 开启这些客户端路由的 SSG 功能。例如上述 `src/App.tsx` 的文件内容为:
|
104
|
-
|
105
|
-
|
106
|
-
<SelfRouteExample />
|
107
|
-
|
108
|
-
在 `modern.config.js` 中这样设置后,`/about` 路由也会开启 SSG 功能:
|
109
|
-
|
110
|
-
```js
|
111
|
-
export default defineConfig({
|
112
|
-
output: {
|
113
|
-
ssg: {
|
114
|
-
routes: ['/', '/about'],
|
115
|
-
},
|
116
|
-
},
|
117
|
-
});
|
118
|
-
```
|
119
|
-
|
120
|
-
Modern.js 将会自动根据入口拼接完整的 URL 并交给 SSG 插件完成渲染。
|
121
|
-
|
122
|
-
也可以为具体入口或路由配置请求头,例如:
|
123
|
-
|
124
|
-
```js
|
125
|
-
export default defineConfig({
|
126
|
-
output: {
|
127
|
-
ssg: {
|
128
|
-
headers: {},
|
129
|
-
routes: [
|
130
|
-
'/',
|
131
|
-
{
|
132
|
-
url: '/about',
|
133
|
-
headers: {},
|
134
|
-
},
|
135
|
-
],
|
136
|
-
},
|
137
|
-
},
|
138
|
-
});
|
139
|
-
```
|
140
|
-
|
141
58
|
:::info
|
142
|
-
|
143
|
-
|
59
|
+
更多关于**约定式路由**和**自控式路由**在开启 SSG 后的默认行为,请阅读 [静态站点生成](/guides/basic-features/render/ssg) 。
|
144
60
|
:::
|
145
61
|
|
146
|
-
|
62
|
+
## Object 类型
|
147
63
|
|
148
|
-
|
64
|
+
当值类型为 `Object` 时,可以配置如下属性。
|
149
65
|
|
150
|
-
|
66
|
+
### 配置类型
|
151
67
|
|
152
|
-
```
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
│ └── user
|
159
|
-
│ ├── layout.tsx
|
160
|
-
│ ├── page.tsx
|
161
|
-
│ └── profile
|
162
|
-
│ └── page.tsx
|
163
|
-
```
|
164
|
-
|
165
|
-
可以这样设置,禁用某一条客户端路由的默认行为:
|
68
|
+
```ts
|
69
|
+
type SSGRouteOptions = string | {
|
70
|
+
url: string;
|
71
|
+
params?: Record<string, any>[];
|
72
|
+
headers?: Record<string, any>;
|
73
|
+
};
|
166
74
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
},
|
173
|
-
},
|
174
|
-
});
|
75
|
+
type SSGOptions = {
|
76
|
+
preventDefault?: string[];
|
77
|
+
headers?: Record<string, any>;
|
78
|
+
routes?: SSGRouteOptions[];
|
79
|
+
};
|
175
80
|
```
|
176
81
|
|
177
|
-
###
|
82
|
+
### 示例
|
178
83
|
|
179
|
-
|
84
|
+
下面的示例配置中,SSG 会渲染 `/`、`/about` 和 `/user/:id` 三条路由对应的页面。
|
180
85
|
|
181
|
-
|
86
|
+
对于 `/user/:id` 路由,`cookies` 添加到请求头中,同时会将 `params` 中的 `id` 替换为 `modernjs`。
|
182
87
|
|
183
|
-
```
|
88
|
+
```ts title="modern.config.ts"
|
184
89
|
export default defineConfig({
|
185
90
|
output: {
|
186
91
|
ssg: {
|
187
92
|
routes: [
|
93
|
+
'/',
|
94
|
+
'/about',
|
188
95
|
{
|
189
96
|
url: '/user/:id',
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
97
|
+
headers: {
|
98
|
+
cookies: "name=modernjs"
|
99
|
+
},
|
100
|
+
params: [{
|
101
|
+
id: 'modernjs',
|
102
|
+
}],
|
103
|
+
}
|
196
104
|
],
|
197
|
-
}
|
198
|
-
}
|
105
|
+
}
|
106
|
+
}
|
199
107
|
});
|
200
108
|
```
|
201
109
|
|
202
|
-
|
110
|
+
:::note
|
111
|
+
多入口的情况和单入口的配置方式一致,这里不再额外介绍。
|
112
|
+
:::
|
@@ -1,5 +1,4 @@
|
|
1
1
|
[
|
2
|
-
"css",
|
3
2
|
"routes",
|
4
3
|
{
|
5
4
|
"type": "dir",
|
@@ -7,6 +6,13 @@
|
|
7
6
|
"label": "data-solution",
|
8
7
|
"collapsed": true
|
9
8
|
},
|
9
|
+
{
|
10
|
+
"type": "dir",
|
11
|
+
"name": "render",
|
12
|
+
"label": "rendering",
|
13
|
+
"collapsed": true
|
14
|
+
},
|
15
|
+
"css",
|
10
16
|
"alias",
|
11
17
|
"mock",
|
12
18
|
"proxy",
|