@modern-js/main-doc 2.4.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +1 -1
- package/LICENSE +0 -123
- package/README.md +26 -0
- package/en/apis/app/commands.mdx +297 -0
- package/en/apis/app/hooks/_category_.json +2 -5
- package/en/apis/app/hooks/api/framework/lambda.mdx +1 -1
- package/en/apis/app/hooks/api/functions/api.mdx +1 -1
- package/en/apis/app/hooks/server/index_.mdx +2 -1
- package/en/apis/app/hooks/src/pages.mdx +7 -7
- package/en/apis/app/hooks/src/routes.mdx +3 -3
- package/en/apis/app/runtime/_category_.json +1 -5
- package/en/apis/app/runtime/app/define-config.mdx +2 -2
- package/en/apis/app/runtime/core/bootstrap.mdx +1 -1
- package/en/apis/app/runtime/core/create-app.mdx +2 -2
- package/en/apis/app/runtime/core/use-loader.mdx +4 -4
- package/en/apis/app/runtime/core/use-module-apps.mdx +2 -2
- package/en/apis/app/runtime/model/Provider.mdx +2 -2
- package/en/apis/app/runtime/model/auto-actions.mdx +2 -2
- package/en/apis/app/runtime/model/connect.mdx +5 -5
- package/en/apis/app/runtime/model/create-app.mdx +9 -9
- package/en/apis/app/runtime/model/create-store.mdx +3 -3
- package/en/apis/app/runtime/model/handle-effect.mdx +2 -2
- package/en/apis/app/runtime/model/model_.mdx +1 -1
- package/en/apis/app/runtime/model/use-local-model.mdx +1 -1
- package/en/apis/app/runtime/model/use-model.mdx +1 -1
- package/en/apis/app/runtime/model/use-static-model.mdx +4 -4
- package/en/apis/app/runtime/model/use-store.mdx +1 -1
- package/en/apis/app/runtime/router/router.mdx +1 -1
- package/en/apis/app/runtime/ssr/pre-render.mdx +1 -1
- package/en/apis/app/runtime/testing/render.mdx +1 -1
- package/en/apis/app/runtime/testing/renderApp.mdx +1 -1
- package/en/apis/app/runtime/utility/css-in-js.mdx +1 -1
- package/en/apis/app/runtime/utility/loadable.mdx +1 -1
- package/en/apis/app/runtime/web-server/hook.mdx +5 -5
- package/en/apis/app/runtime/web-server/middleware.mdx +6 -6
- package/en/components/global-proxy-config.mdx +3 -3
- package/en/components/init-app.mdx +5 -5
- package/en/configure/app/bff/_category_.json +4 -0
- package/en/configure/app/bff/prefix.mdx +2 -3
- package/en/configure/app/bff/proxy.mdx +1 -1
- package/en/configure/app/builder-plugins.mdx +3 -3
- package/en/configure/app/deploy/_category_.json +4 -0
- package/en/configure/app/dev/_category_.json +4 -0
- package/en/configure/app/dev/asset-prefix.mdx +1 -1
- package/en/configure/app/dev/before-start-url.mdx +13 -0
- package/en/configure/app/dev/hmr.mdx +1 -1
- package/en/configure/app/dev/host.mdx +13 -0
- package/en/configure/app/dev/https.mdx +1 -1
- package/en/configure/app/dev/port.mdx +1 -1
- package/en/configure/app/dev/progress-bar.mdx +1 -1
- package/en/configure/app/dev/start-url.mdx +1 -1
- package/en/configure/app/experiments/_category_.json +4 -0
- package/en/configure/app/experiments/lazy-compilation.mdx +1 -1
- package/en/configure/app/html/_category_.json +4 -0
- package/en/configure/app/html/app-icon.mdx +1 -1
- package/en/configure/app/html/crossorigin.mdx +1 -1
- package/en/configure/app/html/disable-html-folder.mdx +1 -1
- package/en/configure/app/html/favicon-by-entries.mdx +1 -1
- package/en/configure/app/html/favicon.mdx +1 -1
- package/en/configure/app/html/inject-by-entries.mdx +1 -1
- package/en/configure/app/html/inject.mdx +1 -1
- package/en/configure/app/html/meta-by-entries.mdx +1 -1
- package/en/configure/app/html/meta.mdx +1 -1
- package/en/configure/app/html/mount-id.mdx +1 -1
- package/en/configure/app/html/tags-by-entries.mdx +1 -1
- package/en/configure/app/html/tags.mdx +1 -1
- package/en/configure/app/html/template-by-entries.mdx +1 -1
- package/en/configure/app/html/template-parameters-by-entries.mdx +1 -1
- package/en/configure/app/html/template-parameters.mdx +1 -1
- package/en/configure/app/html/template.mdx +1 -1
- package/en/configure/app/html/title-by-entries.mdx +1 -1
- package/en/configure/app/html/title.mdx +1 -1
- package/en/configure/app/output/_category_.json +4 -0
- package/en/configure/app/output/asset-prefix.mdx +1 -1
- package/en/configure/app/output/assets-retry.mdx +1 -1
- package/en/configure/app/output/charset.mdx +1 -1
- package/en/configure/app/output/clean-dist-path.mdx +1 -1
- package/en/configure/app/output/convert-to-rem.mdx +1 -1
- package/en/configure/app/output/copy.mdx +1 -1
- package/en/configure/app/output/css-module-local-ident-name.mdx +1 -1
- package/en/configure/app/output/data-uri-limit.mdx +1 -1
- package/en/configure/app/output/disable-css-extract.mdx +1 -1
- package/en/configure/app/output/disable-css-module-extension.mdx +1 -1
- package/en/configure/app/output/disable-filename-hash.mdx +1 -1
- package/en/configure/app/output/disable-inline-runtime-chunk.mdx +1 -1
- package/en/configure/app/output/disable-minimize.mdx +1 -1
- package/en/configure/app/output/disable-source-map.mdx +1 -1
- package/en/configure/app/output/disable-ts-checker.mdx +1 -1
- package/en/configure/app/output/dist-path.mdx +1 -1
- package/en/configure/app/output/enable-asset-fallback.mdx +1 -1
- package/en/configure/app/output/enable-asset-manifest.mdx +1 -1
- package/en/configure/app/output/enable-css-module-tsdeclaration.mdx +1 -1
- package/en/configure/app/output/enable-inline-scripts.mdx +1 -1
- package/en/configure/app/output/enable-inline-styles.mdx +1 -1
- package/en/configure/app/output/enable-latest-decorators.mdx +1 -1
- package/en/configure/app/output/externals.mdx +1 -1
- package/en/configure/app/output/filename.mdx +1 -1
- package/en/configure/app/output/legal-comments.mdx +1 -1
- package/en/configure/app/output/override-browserslist.mdx +1 -1
- package/en/configure/app/output/polyfill.mdx +1 -1
- package/en/configure/app/output/ssg.mdx +5 -5
- package/en/configure/app/output/svg-default-export.mdx +1 -1
- package/en/configure/app/performance/_category_.json +4 -0
- package/en/configure/app/performance/build-cache.mdx +1 -1
- package/en/configure/app/performance/bundle-analyze.mdx +1 -1
- package/en/configure/app/performance/chunk-split.mdx +1 -1
- package/en/configure/app/performance/print-file-size.mdx +1 -1
- package/en/configure/app/performance/profile.mdx +1 -1
- package/en/configure/app/performance/remove-console.mdx +1 -1
- package/en/configure/app/performance/remove-moment-locale.mdx +1 -1
- package/en/configure/app/plugins.mdx +1 -1
- package/en/configure/app/runtime/_category_.json +4 -0
- package/en/configure/app/runtime/intro.mdx +2 -2
- package/en/configure/app/runtime/master-app.mdx +1 -1
- package/en/configure/app/security/_category_.json +4 -0
- package/en/configure/app/security/check-syntax.mdx +1 -1
- package/en/configure/app/security/sri.mdx +1 -1
- package/en/configure/app/server/_category_.json +4 -0
- package/en/configure/app/server/base-url.mdx +3 -3
- package/en/configure/app/server/enable-framework-ext.mdx +1 -1
- package/en/configure/app/server/ssr-by-entries.mdx +1 -1
- package/en/configure/app/source/_category_.json +4 -0
- package/en/configure/app/source/alias.mdx +1 -1
- package/en/configure/app/source/compile-js-data-uri.mdx +1 -1
- package/en/configure/app/source/define.mdx +1 -1
- package/en/configure/app/source/design-system.mdx +5 -5
- package/en/configure/app/source/entries-dir.mdx +1 -1
- package/en/configure/app/source/entries.mdx +3 -3
- package/en/configure/app/source/exclude.mdx +1 -1
- package/en/configure/app/source/global-vars.mdx +1 -1
- package/en/configure/app/source/include.mdx +1 -1
- package/en/configure/app/source/module-scopes.mdx +1 -1
- package/en/configure/app/source/pre-entry.mdx +1 -1
- package/en/configure/app/source/resolve-extension-prefix.mdx +1 -1
- package/en/configure/app/source/resolve-main-fields.mdx +1 -1
- package/en/configure/app/testing/_category_.json +4 -0
- package/en/configure/app/testing/transformer.mdx +1 -1
- package/en/configure/app/tools/_category_.json +4 -0
- package/en/configure/app/tools/autoprefixer.mdx +1 -1
- package/en/configure/app/tools/babel.mdx +1 -1
- package/en/configure/app/tools/css-extract.mdx +1 -1
- package/en/configure/app/tools/css-loader.mdx +1 -1
- package/en/configure/app/tools/dev-server.mdx +1 -1
- package/en/configure/app/tools/html-plugin.mdx +1 -1
- package/en/configure/app/tools/inspector.mdx +1 -1
- package/en/configure/app/tools/jest.mdx +1 -1
- package/en/configure/app/tools/less.mdx +1 -1
- package/en/configure/app/tools/minify-css.mdx +1 -1
- package/en/configure/app/tools/postcss.mdx +1 -1
- package/en/configure/app/tools/pug.mdx +1 -1
- package/en/configure/app/tools/rspack.mdx +13 -0
- package/en/configure/app/tools/sass.mdx +1 -1
- package/en/configure/app/tools/style-loader.mdx +1 -1
- package/en/configure/app/tools/styled-components.mdx +1 -1
- package/en/configure/app/tools/tailwindcss.mdx +1 -1
- package/en/configure/app/tools/terser.mdx +1 -1
- package/en/configure/app/tools/ts-checker.mdx +1 -1
- package/en/configure/app/tools/ts-loader.mdx +1 -1
- package/en/configure/app/tools/webpack-chain.mdx +1 -1
- package/en/configure/app/tools/webpack.mdx +1 -1
- package/en/configure/app/usage.mdx +1 -1
- package/en/guides/advanced-features/_category_.json +2 -2
- package/en/guides/advanced-features/bff/bff-proxy.mdx +1 -1
- package/en/guides/advanced-features/bff/frameworks.mdx +1 -1
- package/en/guides/advanced-features/bff/function.mdx +3 -3
- package/en/guides/advanced-features/code-split.mdx +2 -2
- package/en/guides/advanced-features/compatibility.mdx +2 -3
- package/en/guides/advanced-features/eslint.mdx +4 -4
- package/en/guides/advanced-features/low-level.mdx +1 -1
- package/en/guides/advanced-features/rspack-start.mdx +69 -0
- package/en/guides/advanced-features/ssg.mdx +12 -13
- package/en/guides/advanced-features/ssr.mdx +3 -3
- package/en/guides/advanced-features/testing.mdx +4 -5
- package/en/guides/advanced-features/web-server.mdx +0 -1
- package/en/guides/basic-features/alias.mdx +5 -5
- package/en/guides/basic-features/data-fetch.mdx +25 -12
- package/en/guides/basic-features/env-vars.mdx +1 -1
- package/en/guides/basic-features/html.mdx +11 -11
- package/en/guides/basic-features/mock.mdx +21 -1
- package/en/guides/basic-features/proxy.mdx +2 -2
- package/en/guides/basic-features/routes.mdx +29 -15
- package/en/guides/{basic-features → concept}/builder.mdx +2 -2
- package/en/guides/concept/entries.mdx +11 -11
- package/en/guides/css/_category_.json +5 -0
- package/en/guides/{basic-features/css → css}/less-sass.mdx +1 -1
- package/en/guides/get-started/introduction.mdx +34 -0
- package/en/guides/get-started/quick-start.mdx +4 -4
- package/en/guides/get-started/upgrade.mdx +2 -1
- package/en/guides/topic-detail/_category_.json +2 -2
- package/en/guides/topic-detail/framework-plugin/hook.mdx +1 -1
- package/en/guides/topic-detail/generator/plugin/api/hook/onForged.mdx +1 -1
- package/en/guides/topic-detail/generator/plugin/develop.mdx +1 -1
- package/en/guides/topic-detail/micro-frontend/c02-development.mdx +128 -61
- package/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +73 -42
- package/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +1 -1
- package/en/guides/topic-detail/model/auto-actions.mdx +1 -1
- package/en/guides/topic-detail/model/define-model.mdx +1 -1
- package/en/guides/topic-detail/model/manage-effects.mdx +1 -1
- package/en/guides/topic-detail/model/model-communicate.mdx +1 -1
- package/en/guides/topic-detail/model/quick-start.mdx +2 -2
- package/en/guides/topic-detail/model/test-model.mdx +1 -1
- package/en/guides/topic-detail/model/use-model.mdx +3 -3
- package/en/guides/troubleshooting/_category_.json +2 -2
- package/en/guides/troubleshooting/cli.mdx +1 -1
- package/en/index.md +1 -1
- package/en/tutorials/first-app/_category_.json +1 -1
- package/en/tutorials/first-app/c01-start.mdx +0 -1
- package/en/tutorials/first-app/c03-css.mdx +1 -2
- package/en/tutorials/first-app/c06-model.mdx +1 -1
- package/en/tutorials/first-app/c07-container.mdx +18 -18
- package/en/tutorials/first-app/c08-entries.mdx +24 -25
- package/en/tutorials/foundations/introduction.mdx +17 -34
- package/package.json +3 -3
- package/scripts/config.ts +3 -1
- package/scripts/summary.en.json +1 -1
- package/scripts/summary.zh.json +1 -1
- package/zh/apis/app/commands.mdx +299 -0
- package/zh/apis/app/hooks/_category_.json +2 -5
- package/zh/apis/app/hooks/src/pages.mdx +1 -1
- package/zh/apis/app/hooks/src/routes.mdx +3 -3
- package/zh/apis/app/runtime/_category_.json +1 -5
- package/zh/apis/app/runtime/core/create-app.mdx +1 -1
- package/zh/apis/app/runtime/core/use-module-apps.mdx +81 -40
- package/zh/apis/app/runtime/model/Provider.mdx +2 -2
- package/zh/apis/app/runtime/model/create-app.mdx +7 -7
- package/zh/apis/app/runtime/model/create-store.mdx +2 -2
- package/zh/apis/app/runtime/model/use-local-model.mdx +1 -1
- package/zh/apis/app/runtime/model/use-static-model.mdx +1 -1
- package/zh/apis/app/runtime/model/use-store.mdx +1 -1
- package/zh/apis/app/runtime/testing/renderApp.mdx +1 -1
- package/zh/components/init-app.mdx +5 -5
- package/zh/components/micro-runtime-config.mdx +6 -6
- package/zh/components/release-note.mdx +1 -1
- package/zh/configure/app/bff/prefix.mdx +1 -1
- package/zh/configure/app/bff/proxy.mdx +1 -1
- package/zh/configure/app/builder-plugins.mdx +3 -3
- package/zh/configure/app/dev/before-start-url.mdx +13 -0
- package/zh/configure/app/dev/host.mdx +13 -0
- package/zh/configure/app/output/ssg.mdx +3 -3
- package/zh/configure/app/plugins.mdx +1 -1
- package/zh/configure/app/server/ssr-by-entries.mdx +1 -1
- package/zh/configure/app/source/entries-dir.mdx +1 -1
- package/zh/configure/app/tools/rspack.mdx +13 -0
- package/zh/configure/app/usage.mdx +1 -1
- package/zh/guides/advanced-features/_category_.json +2 -6
- package/zh/guides/advanced-features/compatibility.mdx +0 -1
- package/zh/guides/advanced-features/rspack-start.mdx +69 -0
- package/zh/guides/advanced-features/ssg.mdx +8 -9
- package/zh/guides/advanced-features/ssr.mdx +3 -2
- package/zh/guides/advanced-features/testing.mdx +0 -1
- package/zh/guides/advanced-features/web-server.mdx +0 -1
- package/zh/guides/basic-features/_category_.json +1 -5
- package/zh/guides/basic-features/alias.mdx +5 -5
- package/zh/guides/basic-features/data-fetch.mdx +39 -30
- package/zh/guides/basic-features/html.mdx +10 -9
- package/zh/guides/basic-features/mock.mdx +20 -0
- package/zh/guides/basic-features/routes.mdx +38 -17
- package/zh/guides/{basic-features → concept}/builder.mdx +4 -4
- package/zh/guides/concept/entries.mdx +11 -11
- package/zh/guides/css/_category_.json +5 -0
- package/zh/guides/{basic-features/css → css}/less-sass.mdx +1 -1
- package/zh/guides/{basic-features/css → css}/postcss.mdx +5 -4
- package/zh/guides/{basic-features/css → css}/tailwindcss.mdx +0 -1
- package/zh/guides/get-started/introduction.mdx +31 -0
- package/zh/guides/get-started/quick-start.mdx +4 -5
- package/zh/guides/get-started/upgrade.mdx +2 -1
- package/zh/guides/topic-detail/_category_.json +2 -2
- package/zh/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +1 -1
- package/zh/guides/topic-detail/micro-frontend/c02-development.mdx +25 -0
- package/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +16 -16
- package/zh/guides/topic-detail/model/model-communicate.mdx +1 -1
- package/zh/guides/troubleshooting/_category_.json +2 -2
- package/zh/index.md +1 -1
- package/zh/tutorials/first-app/_category_.json +1 -1
- package/zh/tutorials/first-app/c01-start.mdx +1 -2
- package/zh/tutorials/first-app/c03-css.mdx +1 -2
- package/zh/tutorials/first-app/c06-model.mdx +2 -2
- package/zh/tutorials/first-app/c07-container.mdx +18 -18
- package/zh/tutorials/first-app/c08-entries.mdx +25 -26
- package/zh/tutorials/foundations/introduction.mdx +14 -29
- package/en/apis/app/commands/_category_.json +0 -8
- package/en/apis/app/commands/build.mdx +0 -39
- package/en/apis/app/commands/dev.mdx +0 -61
- package/en/apis/app/commands/index.mdx +0 -7
- package/en/apis/app/commands/inspect.mdx +0 -61
- package/en/apis/app/commands/lint.mdx +0 -19
- package/en/apis/app/commands/new.mdx +0 -54
- package/en/apis/app/commands/serve.mdx +0 -27
- package/en/apis/app/commands/test.mdx +0 -35
- package/en/apis/app/commands/upgrade.mdx +0 -18
- package/en/apis/app/hooks/index.mdx +0 -7
- package/en/apis/app/runtime/index.mdx +0 -7
- package/en/guides/advanced-features/index.mdx +0 -7
- package/en/guides/basic-features/css/_category_.json +0 -4
- package/zh/apis/app/commands/_category_.json +0 -8
- package/zh/apis/app/commands/build.mdx +0 -39
- package/zh/apis/app/commands/dev.mdx +0 -61
- package/zh/apis/app/commands/index.mdx +0 -7
- package/zh/apis/app/commands/inspect.mdx +0 -61
- package/zh/apis/app/commands/lint.mdx +0 -19
- package/zh/apis/app/commands/new.mdx +0 -54
- package/zh/apis/app/commands/serve.mdx +0 -27
- package/zh/apis/app/commands/test.mdx +0 -35
- package/zh/apis/app/commands/upgrade.mdx +0 -18
- package/zh/apis/app/hooks/index.mdx +0 -7
- package/zh/apis/app/runtime/index.mdx +0 -7
- package/zh/guides/advanced-features/index.mdx +0 -7
- package/zh/guides/basic-features/css/_category_.json +0 -4
- package/zh/guides/basic-features/index.mdx +0 -7
- /package/en/guides/{basic-features/css → css}/css-in-js.mdx +0 -0
- /package/en/guides/{basic-features/css → css}/css-modules.mdx +0 -0
- /package/en/guides/{basic-features/css → css}/postcss.mdx +0 -0
- /package/en/guides/{basic-features/css → css}/tailwindcss.mdx +0 -0
- /package/zh/guides/{basic-features/css → css}/css-in-js.mdx +0 -0
- /package/zh/guides/{basic-features/css → css}/css-modules.mdx +0 -0
@@ -25,20 +25,31 @@ import EnableMicroFrontend from "@site-docs/components/enable-micro-frontend";
|
|
25
25
|
|
26
26
|
<EnableMicroFrontend />
|
27
27
|
|
28
|
+
这里演示主应用为自控式路由的场景,全部场景参考 [体验微前端](/guides/topic-detail/micro-frontend/c02-development.html)
|
28
29
|
```tsx title=App.tsx
|
29
30
|
function App() {
|
30
|
-
const {
|
31
|
+
const { apps, MApp, Table, Dashboard } = useModuleApps();
|
32
|
+
|
33
|
+
// 使用的不是 MApp 组件,需要使用 createBrowserRouter 来创建路由
|
34
|
+
const router = createBrowserRouter(
|
35
|
+
createRoutesFromElements(
|
36
|
+
<Route path="/" element={<AppLayout />}>
|
37
|
+
<Route key={'table'} path={'table/*'} element={<Table />} />
|
38
|
+
<Route key={'dashboard'} path={'dashboard/*'} element={<Dashboard />} />
|
39
|
+
</Route>
|
40
|
+
)
|
41
|
+
);
|
31
42
|
|
32
43
|
return (
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
// 方法一:使用 MApp 自动根据配置的 activeWhen 参数加载子应用(本项目配置在 modern.config.ts 中)
|
45
|
+
// <BrowserRouter>
|
46
|
+
// <MApp />
|
47
|
+
// </BrowserRouter>
|
48
|
+
|
49
|
+
// 方法二:手动写 Route 组件方式加载子应用,方便于需要鉴权等需要前置操作的场景
|
50
|
+
<>
|
51
|
+
<RouterProvider router={router} />
|
52
|
+
</>
|
42
53
|
);
|
43
54
|
}
|
44
55
|
|
@@ -47,11 +58,11 @@ defineConfig(App, {
|
|
47
58
|
apps: [
|
48
59
|
{
|
49
60
|
// name 区分大小写,name 提供的是什么 useModuleApps 返回的就是什么
|
50
|
-
name: '
|
61
|
+
name: 'Table',
|
51
62
|
entry: 'http://127.0.0.1:8081/',
|
52
63
|
},
|
53
64
|
{
|
54
|
-
name: '
|
65
|
+
name: 'Dashboard',
|
55
66
|
entry: 'http://localhost:8082',
|
56
67
|
},
|
57
68
|
],
|
@@ -59,7 +70,7 @@ defineConfig(App, {
|
|
59
70
|
});
|
60
71
|
```
|
61
72
|
|
62
|
-
通过 `useModuleApps()` 获取到 `
|
73
|
+
通过 `useModuleApps()` 获取到 `Table` 和 `Dashboard` 子应用组件(名称和配置里的 `name` 字段对应),之后就可以像使用普通的 React 组件一样去加载子应用。
|
63
74
|
|
64
75
|
### 集中式路由
|
65
76
|
|
@@ -89,13 +100,13 @@ defineConfig(App, {
|
|
89
100
|
apps: [
|
90
101
|
{
|
91
102
|
// name 区分大小写,name 提供的是什么 useModuleApps 返回的就是什么
|
92
|
-
name: '
|
93
|
-
activeWhen: '/
|
103
|
+
name: 'Table',
|
104
|
+
activeWhen: '/table',
|
94
105
|
entry: 'http://127.0.0.1:8081/',
|
95
106
|
},
|
96
107
|
{
|
97
|
-
name: '
|
98
|
-
activeWhen: '/
|
108
|
+
name: 'Dashboard',
|
109
|
+
activeWhen: '/dashboard',
|
99
110
|
entry: 'http://localhost:8082',
|
100
111
|
},
|
101
112
|
],
|
@@ -103,36 +114,66 @@ defineConfig(App, {
|
|
103
114
|
});
|
104
115
|
```
|
105
116
|
|
106
|
-
这样启动应用后,访问 `/dashboard` 路由,会渲染 `Dashboard` 子应用,访问 `/table` 路由,会渲染 `
|
117
|
+
这样启动应用后,访问 `/dashboard` 路由,会渲染 `Dashboard` 子应用,访问 `/table` 路由,会渲染 `Table` 子应用。
|
107
118
|
|
108
119
|
## 加载动画
|
109
120
|
|
110
121
|
可以通过以下方式,自定义组件加载过程的过渡动画。
|
111
122
|
|
112
|
-
```
|
113
|
-
|
114
|
-
const { Home } = useModuleApps();
|
123
|
+
```js title="App.tsx"
|
124
|
+
import { useModuleApps } from '@modern-js/plugin-garfish/runtime';
|
115
125
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
126
|
+
import { RouterProvider, Route, createBrowserRouter, createRoutesFromElements, BrowserRouter, Link, Outlet } from '@modern-js/runtime/router';
|
127
|
+
|
128
|
+
const AppLayout = () => (
|
129
|
+
<>
|
130
|
+
<div><Link to={'/table'}>加载约定式路由子应用</Link></div>
|
131
|
+
<div><Link to={'/dashboard'}>加载自控式路由子应用</Link></div>
|
132
|
+
<div><Link to={'/'}>卸载子应用</Link></div>
|
133
|
+
<Outlet />
|
134
|
+
</>
|
135
|
+
)
|
136
|
+
|
137
|
+
export default () => {
|
138
|
+
const { apps } = useModuleApps();
|
139
|
+
|
140
|
+
// 使用的不是 MApp 组件,需要使用 createBrowserRouter 来创建路由
|
141
|
+
const router = createBrowserRouter(
|
142
|
+
createRoutesFromElements(
|
143
|
+
<Route path="/" element={<AppLayout />}>
|
144
|
+
{apps.map(app => {
|
145
|
+
const { Component } = app;
|
146
|
+
// 模糊匹配,path 需要写成类似 abc/* 的模式
|
147
|
+
return (
|
148
|
+
<Route
|
149
|
+
key={app.name}
|
150
|
+
path={`${app.name.toLowerCase()}/*`}
|
151
|
+
element={
|
152
|
+
<Component
|
153
|
+
loadable={{
|
154
|
+
loading: ({ pastDelay, error }: any) => {
|
155
|
+
if (error) {
|
156
|
+
return <div>error: {error?.message}</div>;
|
157
|
+
} else if (pastDelay) {
|
158
|
+
return <div>loading</div>;
|
159
|
+
} else {
|
160
|
+
return null;
|
161
|
+
}
|
162
|
+
},
|
163
|
+
}}
|
164
|
+
/>
|
130
165
|
}
|
131
|
-
|
132
|
-
|
133
|
-
|
166
|
+
/>
|
167
|
+
)
|
168
|
+
})}
|
134
169
|
</Route>
|
135
|
-
|
170
|
+
)
|
136
171
|
);
|
137
|
-
|
172
|
+
|
173
|
+
return (
|
174
|
+
<>
|
175
|
+
<RouterProvider router={router} />
|
176
|
+
</>
|
177
|
+
);
|
178
|
+
};
|
138
179
|
```
|
@@ -21,8 +21,8 @@ interface ProviderProps {
|
|
21
21
|
|
22
22
|
### 参数
|
23
23
|
|
24
|
-
- store:[`createStore`](./create-store.
|
25
|
-
- config:创建 Reduck Store 的配置,同 [`createApp`](./create-app.
|
24
|
+
- store:[`createStore`](./create-store.mdx) 创建的 Store 对象。
|
25
|
+
- config:创建 Reduck Store 的配置,同 [`createApp`](./create-app.mdx) 的 `config` 参数。
|
26
26
|
|
27
27
|
## 示例
|
28
28
|
|
@@ -29,19 +29,19 @@ function createApp(config: AppConfig): object;
|
|
29
29
|
### 参数
|
30
30
|
|
31
31
|
- config:`Record<string, any>`
|
32
|
-
- StoreConfig:同 [`createStore`](./create-store.
|
32
|
+
- StoreConfig:同 [`createStore`](./create-store.mdx) 的参数。
|
33
33
|
- devTools:默认值为 true。是否开启 Redux DevTools,当为对象类型时,支持配置 Redux DevTools 的 [Options](https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md)。
|
34
|
-
- autoActions:默认值为 true。是否[自动生成 Actions](./auto-actions.
|
34
|
+
- autoActions:默认值为 true。是否[自动生成 Actions](./auto-actions.mdx)。
|
35
35
|
|
36
36
|
### 返回值
|
37
37
|
|
38
38
|
Reduck App,有以下属性组成:
|
39
39
|
|
40
|
-
- Provider:为应用局部的组件树注入共享 Store 的组件。用法同 [`Provider`](./Provider.
|
41
|
-
- useModel:获取应用局部 Store 挂载的 Model 对象。用法同 [`useModel`](./use-model.
|
42
|
-
- useStaticModel:获取应用局部 Store 挂载的 Model 对象。用法同 [`useStaticModel`](./use-static-model.
|
43
|
-
- useLocalModel:获取应用局部 Store 挂载的 Model 对象。用法同 [`useLocalModel`](./use-local-model.
|
44
|
-
- useStore:获取应用局部使用的 Store 对象。用法同 [`useStore`](./use-store.
|
40
|
+
- Provider:为应用局部的组件树注入共享 Store 的组件。用法同 [`Provider`](./Provider.mdx)。
|
41
|
+
- useModel:获取应用局部 Store 挂载的 Model 对象。用法同 [`useModel`](./use-model.mdx)。
|
42
|
+
- useStaticModel:获取应用局部 Store 挂载的 Model 对象。用法同 [`useStaticModel`](./use-static-model.mdx)。
|
43
|
+
- useLocalModel:获取应用局部 Store 挂载的 Model 对象。用法同 [`useLocalModel`](./use-local-model.mdx)。
|
44
|
+
- useStore:获取应用局部使用的 Store 对象。用法同 [`useStore`](./use-store.mdx)。
|
45
45
|
|
46
46
|
## 示例
|
47
47
|
|
@@ -10,7 +10,7 @@ import ReduckTip from "@site-docs/components/reduck-tip"
|
|
10
10
|
|
11
11
|
`createStore` 用于创建一个 Store 对象。Reduck 的 Store 基于 Redux 的 [Store](https://redux.js.org/api/store) 实现,用于存储应用的状态,同时提供一组用于管理状态和 Model 的方法。
|
12
12
|
|
13
|
-
一般情况下,不需要使用这个 API,只有需要完全掌控 Store 的创建时,才会使用这个 API。例如,自定义一个 Store,传入 [`Provider`](./Provider.
|
13
|
+
一般情况下,不需要使用这个 API,只有需要完全掌控 Store 的创建时,才会使用这个 API。例如,自定义一个 Store,传入 [`Provider`](./Provider.mdx) 组件使用。
|
14
14
|
|
15
15
|
## 函数签名
|
16
16
|
|
@@ -44,7 +44,7 @@ function createStore(config: StoreConfig): ReduckStore;
|
|
44
44
|
|
45
45
|
Reduck Store 对象:
|
46
46
|
|
47
|
-
- use:动态挂载和获取 Model 对象。用法与 [`useModel`](./use-model.
|
47
|
+
- use:动态挂载和获取 Model 对象。用法与 [`useModel`](./use-model.mdx) 相同,但可以在 React 组件外使用。
|
48
48
|
- unmount:卸载 Model 对象,Model 的 State 会从 Store 中清除。
|
49
49
|
- ReduxStore:Redux Store 对象具有的方法,[详见](https://redux.js.org/tutorials/fundamentals/part-4-store#redux-store)。
|
50
50
|
|
@@ -8,7 +8,7 @@ import ReduckTip from "@site-docs/components/reduck-tip"
|
|
8
8
|
|
9
9
|
<ReduckTip />
|
10
10
|
|
11
|
-
用于把 Model 中的 State 作为局部状态使用,效果类似 React 的 `useState`。`useLocalModel` API 形式上与 `useModel` 完全一致。具体使用请参考 [`useModel`](./use-model.
|
11
|
+
用于把 Model 中的 State 作为局部状态使用,效果类似 React 的 `useState`。`useLocalModel` API 形式上与 `useModel` 完全一致。具体使用请参考 [`useModel`](./use-model.mdx)。
|
12
12
|
|
13
13
|
#### 示例
|
14
14
|
|
@@ -8,7 +8,7 @@ import ReduckTip from "@site-docs/components/reduck-tip"
|
|
8
8
|
|
9
9
|
<ReduckTip />
|
10
10
|
|
11
|
-
如果想在组件里以 React Hook 的形式消费某个 Model,并能随时获取到当前最新的状态,但又不希望 Model 状态更新的时候,引起组件的重新渲染,可以使用 `useStaticModel`。`useStaticModel` API 形式上与 `useModel` 完全一致。具体使用请参考 [`useModel`](./use-model.
|
11
|
+
如果想在组件里以 React Hook 的形式消费某个 Model,并能随时获取到当前最新的状态,但又不希望 Model 状态更新的时候,引起组件的重新渲染,可以使用 `useStaticModel`。`useStaticModel` API 形式上与 `useModel` 完全一致。具体使用请参考 [`useModel`](./use-model.mdx)。
|
12
12
|
|
13
13
|
为了保证总是能获取到最新状态,注意不要对返回的 `state` 解构。
|
14
14
|
|
@@ -18,7 +18,7 @@ function useStore(): ReduckStore;
|
|
18
18
|
|
19
19
|
### 返回值
|
20
20
|
|
21
|
-
- ReduckStore:Reduck Store,类型参考 [createStore](./create-store.
|
21
|
+
- ReduckStore:Reduck Store,类型参考 [createStore](./create-store.mdx) 返回值。
|
22
22
|
|
23
23
|
:::info 更多参考
|
24
24
|
[使用 Model](/guides/topic-detail/model/use-model#在组件外使用)
|
@@ -31,11 +31,11 @@ Modern.js 生成器除了在项目初始化时工作外,也能在后续研发
|
|
31
31
|
.
|
32
32
|
├── node_modules
|
33
33
|
├── src
|
34
|
-
│
|
35
|
-
│
|
36
|
-
│
|
37
|
-
│
|
38
|
-
│
|
34
|
+
│ ├── modern-app-env.d.ts
|
35
|
+
│ └── routes
|
36
|
+
│ ├── index.css
|
37
|
+
│ ├── layout.tsx
|
38
|
+
│ └── page.tsx
|
39
39
|
├── modern.config.ts
|
40
40
|
├── package.json
|
41
41
|
├── pnpm-lock.yaml
|
@@ -4,13 +4,13 @@ import { defineConfig } from '@modern-js/runtime';
|
|
4
4
|
defineConfig(App, {
|
5
5
|
masterApp: {
|
6
6
|
apps: [{
|
7
|
-
name: '
|
8
|
-
entry: 'http://localhost:
|
9
|
-
// activeWhen: '/
|
7
|
+
name: 'Table',
|
8
|
+
entry: 'http://localhost:8001',
|
9
|
+
// activeWhen: '/table'
|
10
10
|
}, {
|
11
|
-
name: '
|
12
|
-
entry: 'http://localhost:
|
13
|
-
// activeWhen: '/
|
11
|
+
name: 'Dashboard',
|
12
|
+
entry: 'http://localhost:8002'
|
13
|
+
// activeWhen: '/dashboard'
|
14
14
|
}]
|
15
15
|
},
|
16
16
|
});
|
@@ -1 +1 @@
|
|
1
|
-
根据官网 [Release Note](https://github.com/modern-js-dev/modern.js/releases
|
1
|
+
根据官网 [Release Note](https://github.com/modern-js-dev/modern.js/releases),开发者也可以手动将项目升级到想要的版本。
|
@@ -9,7 +9,7 @@ sidebar_position: 10
|
|
9
9
|
|
10
10
|
用于配置 Modern.js Builder 构建插件。
|
11
11
|
|
12
|
-
Modern.js Builder 是 Modern.js 底层的构建引擎,请阅读 [构建能力](/guides/
|
12
|
+
Modern.js Builder 是 Modern.js 底层的构建引擎,请阅读 [构建能力](/guides/concept/builder) 了解相关背景。
|
13
13
|
|
14
14
|
如果你想了解 Builder 插件的编写方式,可以参考 [Modern.js Builder - 插件系统](https://modernjs.dev/builder/plugins/introduction.html)。
|
15
15
|
|
@@ -17,13 +17,13 @@ Modern.js Builder 是 Modern.js 底层的构建引擎,请阅读 [构建能力]
|
|
17
17
|
|
18
18
|
该选项**用于配置 Modern.js Builder 构建插件**,如果你需要配置其他类型的插件,请选择对应的配置方式:
|
19
19
|
|
20
|
-
- 配置 Modern.js 框架插件,请使用 [plugins](
|
20
|
+
- 配置 Modern.js 框架插件,请使用 [plugins](/configure/app/plugins) 配置项。
|
21
21
|
- 配置 webpack 插件,请使用 [tools.webpack](/configure/app/tools/webpack) 或 [tools.webpackChain](/configure/app/tools/webpack-chain) 配置项。
|
22
22
|
- 配置 Babel 插件,请使用 [tools.babel](/configure/app/tools/babel) 配置项。
|
23
23
|
|
24
24
|
## 何时使用
|
25
25
|
|
26
|
-
大部分场景下,我们推荐你使用 Modern.js 框架插件,框架插件可以通过 [plugins](
|
26
|
+
大部分场景下,我们推荐你使用 Modern.js 框架插件,框架插件可以通过 [plugins](/configure/app/plugins) 字段进行注册。因为框架插件提供的 API 更丰富、能力更强,而 Builder 插件提供的 API 只能用于构建场景。
|
27
27
|
|
28
28
|
当你需要引用一些现有的 Builder 插件(并且在 Modern.js 中没有相关能力),或是在不同的框架之间复用 Builder 插件时,你可以使用 `builderPlugins` 字段进行注册。
|
29
29
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
sidebar_label: beforeStartUrl
|
3
|
+
---
|
4
|
+
|
5
|
+
# dev.beforeStartUrl
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [dev.beforeStartUrl](https://modernjs.dev/builder/api/config-dev.html#devbeforestarturl)。
|
9
|
+
:::
|
10
|
+
|
11
|
+
import Main from '@modern-js/builder-doc/docs/zh/config/dev/beforeStartUrl.md'
|
12
|
+
|
13
|
+
<Main />
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
sidebar_label: host
|
3
|
+
---
|
4
|
+
|
5
|
+
# dev.host
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [dev.host](https://modernjs.dev/builder/api/config-dev.html#devhost)。
|
9
|
+
:::
|
10
|
+
|
11
|
+
import Main from '@modern-js/builder-doc/docs/zh/config/dev/host.md'
|
12
|
+
|
13
|
+
<Main />
|
@@ -66,7 +66,7 @@ import SelfRouteExample from "@site-docs/components/self-route-example";
|
|
66
66
|
```bash
|
67
67
|
。
|
68
68
|
├── src
|
69
|
-
│
|
69
|
+
│ ├── entryA
|
70
70
|
│ │ └── routes
|
71
71
|
│ │ ├── layout.tsx
|
72
72
|
│ │ ├── page.tsx
|
@@ -75,8 +75,8 @@ import SelfRouteExample from "@site-docs/components/self-route-example";
|
|
75
75
|
│ │ ├── page.tsx
|
76
76
|
│ │ └── profile
|
77
77
|
│ │ └── page.tsx
|
78
|
-
│
|
79
|
-
│
|
78
|
+
│ └── entryB
|
79
|
+
│ └── App.tsx
|
80
80
|
```
|
81
81
|
|
82
82
|
默认情况下,所有约定式路由的入口,在设置 `output.ssg` 配置为 `true` 后都会在构建阶段渲染。可以配置 `false` 来取消指定入口的的默认行为,例如取消上述 entryA 入口在构建时的渲染:
|
@@ -15,7 +15,7 @@ sidebar_position: 9
|
|
15
15
|
|
16
16
|
该选项**用于配置框架插件**,如果你需要配置其他类型的插件,请选择对应的配置方式:
|
17
17
|
|
18
|
-
- 配置 Modern.js Builder 插件,请使用 [builderPlugins](
|
18
|
+
- 配置 Modern.js Builder 插件,请使用 [builderPlugins](/configure/app/builder-plugins) 配置项。
|
19
19
|
- 配置 webpack 插件,请使用 [tools.webpack](/configure/app/tools/webpack) 或 [tools.webpackChain](/configure/app/tools/webpack-chain) 配置项。
|
20
20
|
- 配置 Babel 插件,请使用 [tools.babel](/configure/app/tools/babel) 配置项。
|
21
21
|
|
@@ -7,7 +7,7 @@ sidebar_label: ssrByEntries
|
|
7
7
|
- **类型:** `Object`
|
8
8
|
- **默认值:** `undefined`
|
9
9
|
|
10
|
-
按入口设置 ssr 选项,选项内的属性同 [ssr](./ssr.
|
10
|
+
按入口设置 ssr 选项,选项内的属性同 [ssr](./ssr.mdx),指定值会和 ssr 属性内容做替换合并操作,例如:
|
11
11
|
|
12
12
|
:::info
|
13
13
|
「 入口名 」默认为目录名,少数情况下通过 `source.entries` 自定义入口时,入口名为 `source.entries` 对象的 `key`。
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
sidebar_label: rspack
|
3
|
+
---
|
4
|
+
|
5
|
+
# tools.rspack
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.rspack](https://modernjs.dev/builder/api/config-tools.html#toolsrspack)。
|
9
|
+
:::
|
10
|
+
|
11
|
+
import Main from '@modern-js/builder-doc/docs/zh/config/tools/rspack.md'
|
12
|
+
|
13
|
+
<Main />
|
@@ -12,7 +12,7 @@ Modern.js 中有两种配置,一个是编译时配置,一个是服务端运
|
|
12
12
|
- `package.json` 文件
|
13
13
|
|
14
14
|
:::info
|
15
|
-
不支持同时在 package.json 中和 modern.config.ts 中配置同一个配置项,推荐优先在 modern.config.ts 中进行配置。如果 Modern.js 检测到重复配置导致的冲突,将会抛出警告。
|
15
|
+
Modern.js 不支持同时在 package.json 中和 modern.config.ts 中配置同一个配置项,推荐优先在 modern.config.ts 中进行配置。如果 Modern.js 检测到重复配置导致的冲突,将会抛出警告。
|
16
16
|
:::
|
17
17
|
|
18
18
|
服务端运行时配置可以在根路径下的 `modern.server-runtime.config.(ts|js|mjs)` 中自定义配置选项。
|
@@ -55,7 +55,6 @@ Modern.js 中还提供了基于浏览器 [UA](https://developer.mozilla.org/zh-C
|
|
55
55
|
```ts title="modern.config.ts"
|
56
56
|
import polyfillPlugin from '@modern-js/plugin-polyfill';
|
57
57
|
|
58
|
-
// https://modernjs.dev/docs/apis/app/config
|
59
58
|
export default defineConfig({
|
60
59
|
plugins: [..., polyfillPlugin()],
|
61
60
|
});
|
@@ -0,0 +1,69 @@
|
|
1
|
+
---
|
2
|
+
title: 使用 Rspack
|
3
|
+
sidebar_position: 12
|
4
|
+
---
|
5
|
+
|
6
|
+
# 使用 Rspack
|
7
|
+
|
8
|
+
[Rspack](https://www.rspack.org/) 是字节跳动 Web Infra 团队自研的 Rust Bundler,核心架构对齐 webpack 实现,并对社区常用的构建能力做了开箱即用的支持。
|
9
|
+
|
10
|
+
Rspack 通过以下方式来提升编译性能:
|
11
|
+
|
12
|
+
- 高度 LTO 优化的 Native code。
|
13
|
+
- 充分利用多核优势,整个编译过程充分进行多线程优化。
|
14
|
+
- 基于请求的按需编译(Lazy Compilation),减小每次编译的模块数目,以提升冷启动的速度。
|
15
|
+
|
16
|
+
## 初始化 rspack 项目
|
17
|
+
|
18
|
+
Modern.js 生成器会提供一个可交互的问答界面,只需将构建工具选择为**rspack**,即可创建一个 rspack 项目:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
$ npx @modern-js/create myapp
|
22
|
+
? 请选择你想创建的工程类型 应用
|
23
|
+
? 请选择开发语言 TS
|
24
|
+
? 请选择包管理工具 pnpm
|
25
|
+
? 请选择构建工具 rspack
|
26
|
+
```
|
27
|
+
|
28
|
+
项目创建完成后,在项目中执行 `pnpm run dev` 即可体验项目。更多项目信息可参考[快速上手](/guides/get-started/quick-start.html)。
|
29
|
+
|
30
|
+
:::tip
|
31
|
+
使用 rspack 作为打包工具时,以下功能暂不支持使用:
|
32
|
+
|
33
|
+
- 服务端渲染(SSR)
|
34
|
+
- 静态站点生成(SSG)
|
35
|
+
- 微前端(Micro Frontend)
|
36
|
+
- Storybook 调试
|
37
|
+
|
38
|
+
:::
|
39
|
+
|
40
|
+
## 从 webpack 迁移至 rspack
|
41
|
+
|
42
|
+
通过执行 `pnpm run new` 可启用 rspack 构建:
|
43
|
+
|
44
|
+
```bash
|
45
|
+
$ pnpm run new
|
46
|
+
? 请选择你想要的操作 启用可选功能
|
47
|
+
? 启用可选功能 启用「rspack 构建」
|
48
|
+
```
|
49
|
+
|
50
|
+
执行命令后,在 modern.config.ts 中开启 rspack 构建:
|
51
|
+
|
52
|
+
```ts title=modern.config.ts
|
53
|
+
import appTools, { defineConfig } from '@modern-js/app-tools';
|
54
|
+
|
55
|
+
export default defineConfig<'rspack'>({
|
56
|
+
runtime: {
|
57
|
+
router: true,
|
58
|
+
},
|
59
|
+
plugins: [
|
60
|
+
appTools({
|
61
|
+
bundler: 'experimental-rspack',
|
62
|
+
}),
|
63
|
+
],
|
64
|
+
});
|
65
|
+
```
|
66
|
+
|
67
|
+
:::tip
|
68
|
+
从 webpack 迁移至 rspack,会有一些构建和配置能力上的差异,详情可参考:[配置差异](https://modernjs.dev/builder/guide/advanced/rspack-start.html#从-webpack-迁移到-rspack)
|
69
|
+
:::
|
@@ -18,7 +18,6 @@ SSG(Static Site Generation)是一种基于数据与模板,在构建时渲
|
|
18
18
|
```ts title="modern.config.ts"
|
19
19
|
import ssgPlugin from '@modern-js/plugin-ssg';
|
20
20
|
|
21
|
-
// https://modernjs.dev/docs/apis/app/config
|
22
21
|
export default defineConfig({
|
23
22
|
output: {
|
24
23
|
ssg: true,
|
@@ -38,14 +37,14 @@ SSG 在**约定式路由**和**自控式路由**下的使用方式不同。
|
|
38
37
|
```
|
39
38
|
.
|
40
39
|
├── src
|
41
|
-
│
|
42
|
-
│
|
43
|
-
│
|
44
|
-
│
|
45
|
-
│
|
46
|
-
│
|
47
|
-
│
|
48
|
-
│
|
40
|
+
│ └── routes
|
41
|
+
│ ├── layout.tsx
|
42
|
+
│ ├── page.tsx
|
43
|
+
│ └── user
|
44
|
+
│ ├── layout.tsx
|
45
|
+
│ ├── page.tsx
|
46
|
+
│ └── profile
|
47
|
+
│ └── page.tsx
|
49
48
|
```
|
50
49
|
|
51
50
|
上述文件目录将会生成以下三条路由:
|
@@ -20,8 +20,8 @@ sidebar_position: 3
|
|
20
20
|
|
21
21
|
Modern.js 中提供了 Data Loader,方便开发者在 SSR、CSR 下同构的获取数据。每个路由模块,如 `layout.tsx` 和 `page.tsx` 都可以定义自己的 Data Loader:
|
22
22
|
|
23
|
-
```ts title="src/routes/page.
|
24
|
-
export
|
23
|
+
```ts title="src/routes/page.loader.ts"
|
24
|
+
export default () => {
|
25
25
|
return {
|
26
26
|
message: 'Hello World',
|
27
27
|
};
|
@@ -31,6 +31,7 @@ export const loader = () => {
|
|
31
31
|
在组件中可以通过 Hooks API 的方式获取 `loader` 函数返回的数据:
|
32
32
|
|
33
33
|
```tsx
|
34
|
+
import { useLoaderData } from '@modern-js/runtime/router'
|
34
35
|
export default () => {
|
35
36
|
const data = useLoaderData();
|
36
37
|
return <div>{data.message}</div>;
|
@@ -20,7 +20,6 @@ Modern.js 默认继承了 [Jest](https://jestjs.io/) 的测试能力。
|
|
20
20
|
```ts title="modern.config.ts"
|
21
21
|
import testPlugin from '@modern-js/plugin-testing';
|
22
22
|
|
23
|
-
// https://modernjs.dev/docs/apis/app/config
|
24
23
|
export default defineConfig({
|
25
24
|
...,
|
26
25
|
plugins: [..., testPlugin()],
|