@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
@@ -23,10 +23,10 @@ Modern.js 允许在 JS 和 CSS 中使用别名导入自定义目录下的模块
|
|
23
23
|
```bash
|
24
24
|
.
|
25
25
|
├── common
|
26
|
-
│
|
27
|
-
│
|
28
|
-
│
|
29
|
-
│
|
26
|
+
│ ├── styles
|
27
|
+
│ │ └── base.css
|
28
|
+
│ └── utils
|
29
|
+
│ └── index.ts
|
30
30
|
├── App.tsx
|
31
31
|
```
|
32
32
|
|
@@ -62,4 +62,4 @@ export default defineConfig({
|
|
62
62
|
});
|
63
63
|
```
|
64
64
|
|
65
|
-
|
65
|
+
对于别名配置的具体用法,请参考 [source.alias 文档](/configure/app/source/alias)。
|
@@ -2,6 +2,7 @@
|
|
2
2
|
title: 数据获取
|
3
3
|
sidebar_position: 3
|
4
4
|
---
|
5
|
+
|
5
6
|
# 数据获取
|
6
7
|
|
7
8
|
Modern.js 中提供了开箱即用的数据获取能力,开发者可以通过这些 API,在 CSR 和 SSR 环境同构的进行开发。
|
@@ -81,9 +82,9 @@ export default async (): Promise<ProfileData> => {
|
|
81
82
|
|
82
83
|
```tsx
|
83
84
|
// routes/user/[id]/page.loader.ts
|
84
|
-
import {
|
85
|
+
import { LoaderFunctionArgs } from '@modern-js/runtime/router';
|
85
86
|
|
86
|
-
export default async ({ params }:
|
87
|
+
export default async ({ params }: LoaderFunctionArgs) => {
|
87
88
|
const { id } = params;
|
88
89
|
const res = await fetch(`https://api/user/${id}`);
|
89
90
|
return res.json();
|
@@ -100,9 +101,9 @@ export default async ({ params }: LoaderArgs) => {
|
|
100
101
|
|
101
102
|
```tsx
|
102
103
|
// routes/user/[id]/page.loader.ts
|
103
|
-
import {
|
104
|
+
import { LoaderFunctionArgs } from '@modern-js/runtime/router';
|
104
105
|
|
105
|
-
export default async ({ request }:
|
106
|
+
export default async ({ request }: LoaderFunctionArgs) => {
|
106
107
|
const url = new URL(request.url);
|
107
108
|
const userId = url.searchParams.get('id');
|
108
109
|
return queryUser(userId);
|
@@ -220,38 +221,46 @@ export default function UserLayout() {
|
|
220
221
|
|
221
222
|
:::
|
222
223
|
|
224
|
+
创建 `user/layout.loader.ts`,并添加以下代码:
|
225
|
+
|
226
|
+
```ts title="routes/user/layout.loader.ts"
|
227
|
+
import { defer } from "@edenx/runtime/router"
|
228
|
+
|
229
|
+
const loader = () =>
|
230
|
+
defer({
|
231
|
+
userInfo: new Promise((resolve) => {
|
232
|
+
setTimeout(() => {
|
233
|
+
resolve({
|
234
|
+
age: 1,
|
235
|
+
name: 'user layout'
|
236
|
+
})
|
237
|
+
}, 1000)
|
238
|
+
})
|
239
|
+
})
|
240
|
+
|
241
|
+
export default loader;
|
242
|
+
```
|
243
|
+
|
223
244
|
在 `user/layout.tsx` 中添加以下代码:
|
224
245
|
|
225
246
|
```tsx title="routes/user/layout.tsx"
|
226
|
-
import {
|
227
|
-
Await,
|
228
|
-
defer,
|
229
|
-
useLoaderData,
|
230
|
-
Outlet
|
231
|
-
} from '@modern-js/runtime/router';
|
232
|
-
|
233
|
-
export const loader = () => {
|
234
|
-
return defer({
|
235
|
-
// fetchUserInfo 是一个异步函数,返回用户信息
|
236
|
-
userInfo: fetchUserInfo(),
|
237
|
-
})
|
238
|
-
}
|
247
|
+
import { Await, defer, useLoaderData, Outlet } from '@modern-js/runtime/router';
|
239
248
|
|
240
249
|
export default function UserLayout() {
|
241
|
-
const { userInfo } = useLoaderData() as {userInfo: Promise<UserInfo>};
|
250
|
+
const { userInfo } = useLoaderData() as { userInfo: Promise<UserInfo> };
|
242
251
|
return (
|
243
252
|
<div>
|
244
|
-
<React.Suspense
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
253
|
+
<React.Suspense fallback={<p>Loading...</p>}>
|
254
|
+
<Await
|
255
|
+
resolve={userInfo}
|
256
|
+
children={userInfo => (
|
257
|
+
<div>
|
258
|
+
<span>{userInfo.name}</span>
|
259
|
+
<span>{userInfo.age}</span>
|
260
|
+
<Outlet />
|
261
|
+
</div>
|
262
|
+
)}
|
263
|
+
></Await>
|
255
264
|
</React.Suspense>
|
256
265
|
</div>
|
257
266
|
);
|
@@ -265,7 +274,7 @@ defer 的具体用法请查看 [defer](https://reactrouter.com/en/main/guides/de
|
|
265
274
|
|
266
275
|
:::
|
267
276
|
|
268
|
-
{/* TODO 缓存相关
|
277
|
+
{/* TODO 缓存相关 */}
|
269
278
|
|
270
279
|
### 错误用法
|
271
280
|
|
@@ -2,9 +2,10 @@
|
|
2
2
|
title: HTML 模板
|
3
3
|
sidebar_position: 9
|
4
4
|
---
|
5
|
+
|
5
6
|
# HTML 模板
|
6
7
|
|
7
|
-
Modern.js 提供了 **JSX
|
8
|
+
Modern.js 提供了 **JSX 语法**和 **HTML(EJS) 语法**两种方式用于自定义 HTML 模板。
|
8
9
|
|
9
10
|
## JSX 语法
|
10
11
|
|
@@ -14,14 +15,14 @@ Modern.js 约定,在 `src/` 目录下,或在入口目录下,可以创建 `
|
|
14
15
|
|
15
16
|
```bash
|
16
17
|
.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
│
|
21
|
-
│
|
22
|
-
|
23
|
-
│
|
24
|
-
|
18
|
+
└── src
|
19
|
+
├── Document.tsx
|
20
|
+
├── entry-a
|
21
|
+
│ ├── Document.tsx
|
22
|
+
│ └── routes
|
23
|
+
├── entry-b
|
24
|
+
│ └── routes
|
25
|
+
└── modern-app-env.d.ts
|
25
26
|
```
|
26
27
|
|
27
28
|
`entry-a` 会优先使用当前入口下的 `Docoument.[jt]sx` 文件。如果当前入口没有 `Document.[jt]sx` 文件,例如 `entry-b`,则会查找根目录下的 `Document.[jt]sx` 文件。
|
@@ -77,3 +77,23 @@ module.exports = {
|
|
77
77
|
},
|
78
78
|
};
|
79
79
|
```
|
80
|
+
|
81
|
+
## 按需使用 Mock 服务
|
82
|
+
|
83
|
+
`config/mock/index.ts` 下还可以到处 `config` 对象,更精细的控制 Mock 服务。
|
84
|
+
|
85
|
+
```ts
|
86
|
+
type MockConfig = {
|
87
|
+
enable: ((req: IncomingMessage, res: ServerResponse) => boolean) | boolean;
|
88
|
+
};
|
89
|
+
|
90
|
+
export const config = {
|
91
|
+
enable: false
|
92
|
+
}
|
93
|
+
```
|
94
|
+
|
95
|
+
目前仅支持 `enable` 配置,开发者可以通过该配置控制是否执行 Mock。
|
96
|
+
|
97
|
+
:::note
|
98
|
+
修改 `config` 后无需重启服务,即刻生效。
|
99
|
+
:::
|
@@ -4,7 +4,7 @@ sidebar_position: 1
|
|
4
4
|
---
|
5
5
|
# 路由
|
6
6
|
|
7
|
-
Modern.js 的路由基于 [React Router 6](https://reactrouter.com/en/main),并提供了多种类型的路由模式。根据不同[入口](/
|
7
|
+
Modern.js 的路由基于 [React Router 6](https://reactrouter.com/en/main),并提供了多种类型的路由模式。根据不同 [入口](/guides/concept/entries) 类型,将路由分为三种模式,分别是**约定式路由**,**自控式路由**和**其他路由方案**。
|
8
8
|
|
9
9
|
:::note
|
10
10
|
本小节提到的路由,都是客户端路由,即 SPA 路由。
|
@@ -109,7 +109,7 @@ export default () => {
|
|
109
109
|
.
|
110
110
|
└── routes
|
111
111
|
├── blog
|
112
|
-
│
|
112
|
+
│ └── page.tsx
|
113
113
|
├── layout.tsx
|
114
114
|
├── page.tsx
|
115
115
|
└── user
|
@@ -156,15 +156,15 @@ export default () => {
|
|
156
156
|
```
|
157
157
|
└── routes
|
158
158
|
├── [id]
|
159
|
-
│
|
159
|
+
│ └── page.tsx
|
160
160
|
├── blog
|
161
|
-
│
|
161
|
+
│ └── page.tsx
|
162
162
|
└── page.tsx
|
163
163
|
```
|
164
164
|
|
165
165
|
`routes/[id]/page.tsx` 文件会转为 `/:id` 路由。除了可以确切匹配的 `/blog` 路由,其他所有 `/xxx` 都会匹配到该路由。
|
166
166
|
|
167
|
-
在组件中,可以通过 [useParams](/apis/app/runtime/router
|
167
|
+
在组件中,可以通过 [useParams](/apis/app/runtime/router/router#useparams) 获取对应命名的参数。
|
168
168
|
|
169
169
|
在 loader 中,params 会作为 [loader](/guides/basic-features/data-fetch#loader-函数) 的入参,通过 `params.xxx` 可以获取。
|
170
170
|
|
@@ -181,11 +181,11 @@ export default () => {
|
|
181
181
|
└── routes
|
182
182
|
├── $.tsx
|
183
183
|
├── blog
|
184
|
-
│
|
184
|
+
│ └── page.tsx
|
185
185
|
└── page.tsx
|
186
186
|
```
|
187
187
|
|
188
|
-
当访问任何匹配不到的路径时,都会渲染 `routes/$.tsx` 组件,同样,`$.tsx` 中可以使用 [useParams](/apis/app/runtime/router
|
188
|
+
当访问任何匹配不到的路径时,都会渲染 `routes/$.tsx` 组件,同样,`$.tsx` 中可以使用 [useParams](/apis/app/runtime/router/router#useparams) 捕获 url 的剩余部分。
|
189
189
|
```ts title="$.tsx"
|
190
190
|
import { useParams } from '@modern-js/runtime/router';
|
191
191
|
// 当 path 是 `/aaa/bbb` 时
|
@@ -248,9 +248,9 @@ Modern.js 会生成 `/login` 和 `/sign` 两条路由,`__auth/layout.tsx` 组
|
|
248
248
|
.
|
249
249
|
└── routes
|
250
250
|
├── blog
|
251
|
-
│
|
252
|
-
│
|
253
|
-
│
|
251
|
+
│ ├── [id]
|
252
|
+
│ │ └── page.tsx
|
253
|
+
│ └── page.tsx
|
254
254
|
├── layout.tsx
|
255
255
|
├── loading.tsx
|
256
256
|
└── page.tsx
|
@@ -292,6 +292,22 @@ Modern.js 建议必须有根 layout 和根 loading。
|
|
292
292
|
|
293
293
|
同理,当路由从 `/` 或者 `/blog` 跳转到 `/blog/123` 时,如果 `blog/[id]/page` 组件的 JS Chunk 还未加载,也会先展示 `loading.tsx` 中导出的组件 UI。
|
294
294
|
|
295
|
+
### 路由重定向
|
296
|
+
|
297
|
+
可以通过创建 [`data loader`](/guides/basic-features/data-fetch) 文件做路由的重定向,如有文件 `routes/user/page.tsx`,想对这个文件对应的路由做重定向,可以创建 `routes/user/page.loader.ts` 文件:
|
298
|
+
|
299
|
+
```ts title="routes/user/page.loader.ts"
|
300
|
+
import { redirect } from "@edenx/runtime/router"
|
301
|
+
|
302
|
+
export default () => {
|
303
|
+
const user = await getUser();
|
304
|
+
if(!user){
|
305
|
+
return redirect('/login');
|
306
|
+
}
|
307
|
+
return null;
|
308
|
+
}
|
309
|
+
```
|
310
|
+
|
295
311
|
### 错误处理
|
296
312
|
|
297
313
|
`routes/` 下每一层目录中,开发者同样可以定义一个 `error.tsx` 文件,默认导出一个 `<ErrorBoundary>` 组件。
|
@@ -302,7 +318,7 @@ Modern.js 建议必须有根 layout 和根 loading。
|
|
302
318
|
|
303
319
|
{/* Todo API 路由 */}
|
304
320
|
|
305
|
-
在 `<ErrorBoundary>` 组件内,可以使用 [useRouteError](/apis/app/runtime/router
|
321
|
+
在 `<ErrorBoundary>` 组件内,可以使用 [useRouteError](/apis/app/runtime/router/router#useparams) 获取的错误的具体信息:
|
306
322
|
|
307
323
|
```tsx
|
308
324
|
import { useRouteError } from '@modern-js/runtime/router';
|
@@ -329,8 +345,15 @@ import type { AppConfig } from '@modern-js/runtime';
|
|
329
345
|
export const config = (): AppConfig => {
|
330
346
|
return {
|
331
347
|
router: {
|
332
|
-
|
333
|
-
|
348
|
+
createRoutes() {
|
349
|
+
return [
|
350
|
+
{
|
351
|
+
path: 'edenx',
|
352
|
+
element: <div>edenx</div>,
|
353
|
+
},
|
354
|
+
];
|
355
|
+
},
|
356
|
+
},
|
334
357
|
}
|
335
358
|
};
|
336
359
|
```
|
@@ -380,12 +403,10 @@ export default () => {
|
|
380
403
|
配合 SSR 功能时,浏览器端可以获取到 SSR 时 `init` 返回的数据,开发者可以自行判断是否要在浏览器端重新获取数据来覆盖 SSR 数据,例如:
|
381
404
|
|
382
405
|
```tsx title="src/routes/layout.tsx"
|
383
|
-
import {
|
384
|
-
RuntimeContext,
|
385
|
-
} from '@modern-js/runtime';
|
406
|
+
import { RuntimeContext } from '@modern-js/runtime';
|
386
407
|
|
387
408
|
export const init = (context: RuntimeContext) => {
|
388
|
-
if (process.env.
|
409
|
+
if (process.env.MODERN_TARGET === 'node') {
|
389
410
|
return {
|
390
411
|
message: 'Hello World By Server',
|
391
412
|
}
|
@@ -1,12 +1,12 @@
|
|
1
1
|
---
|
2
|
-
title: 构建能力
|
3
2
|
sidebar_position: 2
|
4
3
|
---
|
5
|
-
|
4
|
+
|
5
|
+
# 构建引擎
|
6
6
|
|
7
7
|
**Modern.js 的构建能力由 [Modern.js Builder](https://modernjs.dev/builder) 提供。**
|
8
8
|
|
9
|
-
Modern.js Builder 是 Modern.js 体系的核心组件之一,它是一个面向 Web 开发场景的构建引擎,可以脱离 Modern.js 被独立使用。Modern.js Builder 同时支持 webpack 和
|
9
|
+
Modern.js Builder 是 Modern.js 体系的核心组件之一,它是一个面向 Web 开发场景的构建引擎,可以脱离 Modern.js 被独立使用。Modern.js Builder 同时支持 webpack 和 rspack 等多种打包工具,默认情况下使用最成熟的 webpack 进行打包。
|
10
10
|
|
11
11
|
## 构建架构
|
12
12
|
|
@@ -14,7 +14,7 @@ Modern.js Builder 是 Modern.js 体系的核心组件之一,它是一个面向
|
|
14
14
|
|
15
15
|
- 上层研发框架:Modern.js。
|
16
16
|
- 通用构建引擎:Modern.js Builder。
|
17
|
-
- 底层打包工具:webpack 和
|
17
|
+
- 底层打包工具:webpack 和 rspack。
|
18
18
|
|
19
19
|
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/builder-layers-1117.png" style={{ maxWidth: '540px' }} />
|
20
20
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
sidebar_position: 2
|
2
|
+
sidebar_position: 1
|
4
3
|
---
|
4
|
+
|
5
5
|
# 入口
|
6
6
|
|
7
7
|
入口是 Modern.js 默认的文件约定,项目的每一个入口是一张独立的页面,对应一条**服务端路由**。
|
@@ -15,11 +15,11 @@ Modern.js 初始化的项目是单入口的,项目结构如下:
|
|
15
15
|
```
|
16
16
|
.
|
17
17
|
├── src
|
18
|
-
│
|
19
|
-
│
|
20
|
-
│
|
21
|
-
│
|
22
|
-
│
|
18
|
+
│ ├── modern-app-env.d.ts
|
19
|
+
│ └── routes
|
20
|
+
│ ├── index.css
|
21
|
+
│ ├── layout.tsx
|
22
|
+
│ └── page.tsx
|
23
23
|
├── package.json
|
24
24
|
├── modern.config.ts
|
25
25
|
├── pnpm-lock.yaml
|
@@ -41,10 +41,10 @@ Modern.js 可以很方便的将单入口切换成多入口。可以在项目下
|
|
41
41
|
.
|
42
42
|
├── modern-app-env.d.ts
|
43
43
|
├── myapp
|
44
|
-
│
|
45
|
-
│
|
46
|
-
│
|
47
|
-
│
|
44
|
+
│ └── routes
|
45
|
+
│ ├── index.css
|
46
|
+
│ ├── layout.tsx
|
47
|
+
│ └── page.tsx
|
48
48
|
└── new-entry
|
49
49
|
└── routes
|
50
50
|
├── index.css
|
@@ -12,6 +12,6 @@ sidebar_position: 4
|
|
12
12
|
- 如果需要自定义 [sass-loader](https://github.com/webpack-contrib/sass-loader) 的配置,请参考 [tools.less](/configure/app/tools/sass) 配置项。
|
13
13
|
|
14
14
|
:::tip 提示
|
15
|
-
经过 Less 和 Sass 预编译后的 CSS 文件,仍然会经过 Modern.js 内置的 [PostCSS](https://postcss.org/) 的转换,具备良好的浏览器兼容性。相关内容请参考【[PostCSS](/guides/
|
15
|
+
经过 Less 和 Sass 预编译后的 CSS 文件,仍然会经过 Modern.js 内置的 [PostCSS](https://postcss.org/) 的转换,具备良好的浏览器兼容性。相关内容请参考【[PostCSS](/guides/css/postcss)】。
|
16
16
|
|
17
17
|
:::
|
@@ -10,10 +10,11 @@ sidebar_position: 3
|
|
10
10
|
|
11
11
|
1. [Autoprefixer](https://github.com/postcss/autoprefixer) 根据需要支持的浏览器范围,会自动为 CSS 规则添加需要的浏览器厂商前缀。Modern.js 默认支持的浏览器范围为:`['> 0.01%', 'not dead', 'not op_mini all']`。
|
12
12
|
|
13
|
-
:::info
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
:::info 注意
|
14
|
+
|
15
|
+
- 【支持的浏览器范围为:`> 0.01%`】是指浏览器市场份额大于 0.01%。
|
16
|
+
- `not dead` 是指不包含官方不再支持的浏览器和过去 24 个月没有更新的浏览器。
|
17
|
+
- `not op_mini all` 是指不包含 Opera Mini。
|
17
18
|
|
18
19
|
:::
|
19
20
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
title: 介绍
|
3
|
+
sidebar_position: 1
|
4
|
+
---
|
5
|
+
|
6
|
+
# Modern.js 介绍
|
7
|
+
|
8
|
+
**Modern.js** 是基于 React 的渐进式现代 Web 开发框架。
|
9
|
+
|
10
|
+
框架内置多种开箱即用的开发工具,拥有极致的构建性能,支持零配置的渲染范式切换,一体化的 API 调用。并从三种工程方案出发(应用工程方案、模块工程方案,Monorepo 工程方案),支持全链路的前端研发。
|
11
|
+
|
12
|
+
Modern.js 是字节跳动的底层前端研发框架,已经直接或间接的服务上千个应用,包括中后台、PC Web、H5 等多种应用场景。框架覆盖完整的生命周期,拥有完善的插件体系,提供高度定制能力。支持通过生成器插件自定义业务线专属的工程方案,定制各种功能扩展和业务需求,帮助开发者更快速的搭建应用。
|
13
|
+
|
14
|
+
## 为什么使用 Modern.js
|
15
|
+
|
16
|
+
Modern.js 能为开发者提供极致的**开发体验(Development Experience)**,让应用拥有更好的**用户体验(User Experience)**。
|
17
|
+
|
18
|
+
在开发 React 应用过程中,开发者通常需要去为某些功能去设计实现方案,或是使用其他的库、框架来解决这些问题。Modern.js 支持 React 应用所需要的所有配置和工具,并内置**额外的功能和优化**。开发者可以使用 React 构建应用的 UI,然后逐步采用 Modern.js 的功能来解决常见的应用需求,如路由、数据获取、状态管理等。
|
19
|
+
|
20
|
+
它主要包含以下特点:
|
21
|
+
|
22
|
+
- 🪜 **渐进式**:使用最精简的模板创建项目,通过生成器逐步开启插件功能,定制解决方案。
|
23
|
+
- 🏠 **一体化**:开发与生产环境 Web Server 唯一,CSR 和 SSR 同构开发,函数即接口的 API 服务调用。
|
24
|
+
- 📦 **开箱即用**:默认 TS 支持,内置构建、ESLint、调试工具,全功能可测试。
|
25
|
+
- 🌏 **周边生态**:自研状态管理、微前端、模块打包、Monorepo 方案等周边需求。
|
26
|
+
- 🕸 **多种路由模式**:包含自控路由、基于文件约定的路由(嵌套路由)等。
|
27
|
+
- 🚀 **独立构建核心**:支持多种打包工具,深度优化构建产物。
|
28
|
+
|
29
|
+
## 下一步
|
30
|
+
|
31
|
+
如果你希望了解如何使用 Modern.js,可以尝试 [创建第一个应用](/tutorials/first-app/c01-start),或是阅读 [快速上手](/guides/get-started/quick-start)。
|
@@ -1,6 +1,6 @@
|
|
1
1
|
---
|
2
2
|
title: 快速上手
|
3
|
-
sidebar_position:
|
3
|
+
sidebar_position: 2
|
4
4
|
---
|
5
5
|
# 快速上手
|
6
6
|
|
@@ -45,10 +45,9 @@ import DebugApp from "@site-docs/components/debug-app"
|
|
45
45
|
|
46
46
|
可以通过配置文件来开启功能,或覆盖 Modern.js 的默认行为。例如添加如下配置,开启 SSR:
|
47
47
|
|
48
|
-
```ts
|
48
|
+
```ts title="modern.config.ts"
|
49
49
|
import appTools, { defineConfig } from '@modern-js/app-tools';
|
50
50
|
|
51
|
-
// https://modernjs.dev/docs/apis/app/config
|
52
51
|
export default defineConfig({
|
53
52
|
runtime: {
|
54
53
|
router: true,
|
@@ -97,9 +96,9 @@ info File sizes after production build:
|
|
97
96
|
.
|
98
97
|
├── asset-manifest.json
|
99
98
|
├── html
|
100
|
-
│
|
99
|
+
│ └── main
|
101
100
|
├── loader-routes
|
102
|
-
│
|
101
|
+
│ └── main
|
103
102
|
├── modern.config.json
|
104
103
|
├── route.json
|
105
104
|
└── static
|
@@ -251,6 +251,31 @@ export default (props: {basename: string}) => {
|
|
251
251
|
|
252
252
|
在完成了微前端整体开发流程的体验后,你可以进一步了解如何 [开发主应用](/guides/topic-detail/micro-frontend/c03-main-app)
|
253
253
|
|
254
|
+
## Modern.js 微前端和直接使用 Garfish 的区别
|
255
|
+
|
256
|
+
使用纯 `Garfish` API 开发微前端应用时
|
257
|
+
- 主应用:
|
258
|
+
- 安装 Garfish 依赖并使用 `Garfish.run` 注册子应用 [参考](https://www.garfishjs.org/api/run)
|
259
|
+
- 提供一个常驻的 `DOM` 节点供子应用挂载 [参考](https://www.garfishjs.org/api/registerApp#domgetter)
|
260
|
+
- 子应用:
|
261
|
+
- 导出 `provider` [参考](https://www.garfishjs.org/guide/start#2%E5%AF%BC%E5%87%BA-provider-%E5%87%BD%E6%95%B0)
|
262
|
+
- 设置应用的 `basename` [参考](https://www.garfishjs.org/guide/start#3-%E8%AE%BE%E7%BD%AE%E5%BA%94%E7%94%A8%E8%B7%AF%E7%94%B1-basename)
|
263
|
+
|
264
|
+
区别于直接使用 `Garfish` 运行时 API 开发微前端项目,`Modern.js` 的微前端方案更加开箱即用。
|
265
|
+
使用 `pnpm new` 启用微前端模式后会自动在 `Modern.js` 应用中集成 `Garfish` 插件,在 `Garfish`
|
266
|
+
插件的加持下,你只需要
|
267
|
+
- 主应用:
|
268
|
+
- 配置 `runtime.masterApp.apps` 参数注册子应用
|
269
|
+
- 使用 `useModuleApps` API 获取子应用实例并在组件中完成渲染
|
270
|
+
- 子应用:
|
271
|
+
- 配置 `deploy.microFrontend`
|
272
|
+
|
273
|
+
所以插件中为你做了如下事情
|
274
|
+
- 帮助你通过 `Garfish` 运行时 API 自动注册子应用(主应用)
|
275
|
+
- `useModulesApps` 函数的返回值提供了一个常驻的 `DOM` 节点供子应用挂载(主应用)
|
276
|
+
- 帮助你正确导出了 `provider`(子应用)
|
277
|
+
- 帮助你正确设置了 `basename` 给 `Modern.js` 运行时提供 `Router` 实例,如果是`自控式路由`或`手动引入的 react-router-dom` 那么需要从 `App.tsx` 的 `props` 中获取 `basename` 手动传递给引入的 `Router 实例`(子应用)
|
278
|
+
|
254
279
|
## 常见问题
|
255
280
|
|
256
281
|
自查手册: https://www.garfishjs.org/issues/
|
@@ -4,7 +4,7 @@ title: 开发主应用
|
|
4
4
|
---
|
5
5
|
# 开发主应用
|
6
6
|
|
7
|
-
在上一章 [体验微前端](/guides/topic-detail/micro-frontend/c02-development
|
7
|
+
在上一章 [体验微前端](/guides/topic-detail/micro-frontend/c02-development) 通过一个示例演示了如何创建和配置微前端子应用,通过本章你可以进一步了解如何开发主应用,以及它的常见配置。
|
8
8
|
|
9
9
|
在通过 `@modern-js/create` 命令创建应用工程后,可以在项目中执行 `pnpm run new`(实际执行了 `modern new` 命令),在选择了「微前端」模式后,会安装微前端依赖依赖,只需手动注册插件即可。
|
10
10
|
|
@@ -41,13 +41,13 @@ defineConfig(App, {
|
|
41
41
|
getAppList: async () => {
|
42
42
|
// 可以从其他远程接口获取
|
43
43
|
return [{
|
44
|
-
name: '
|
45
|
-
entry: 'http://localhost:
|
46
|
-
// activeWhen: '/
|
44
|
+
name: 'Table',
|
45
|
+
entry: 'http://localhost:8001',
|
46
|
+
// activeWhen: '/table'
|
47
47
|
}, {
|
48
|
-
name: '
|
49
|
-
entry: 'http://localhost:
|
50
|
-
// activeWhen: '/
|
48
|
+
name: 'Dashboard',
|
49
|
+
entry: 'http://localhost:8002'
|
50
|
+
// activeWhen: '/dashboard'
|
51
51
|
}];
|
52
52
|
},
|
53
53
|
},
|
@@ -81,8 +81,8 @@ import { RouterProvider, Route, createBrowserRouter, createRoutesFromElements, B
|
|
81
81
|
|
82
82
|
const AppLayout = () => (
|
83
83
|
<>
|
84
|
-
<div><Link to={'/
|
85
|
-
<div><Link to={'/
|
84
|
+
<div><Link to={'/table'}>加载约定式路由子应用</Link></div>
|
85
|
+
<div><Link to={'/dashboard'}>加载自控式路由子应用</Link></div>
|
86
86
|
<div><Link to={'/'}>卸载子应用</Link></div>
|
87
87
|
<Outlet />
|
88
88
|
</>
|
@@ -101,7 +101,7 @@ export default () => {
|
|
101
101
|
return (
|
102
102
|
<Route
|
103
103
|
key={app.name}
|
104
|
-
path={`${app.name}/*`}
|
104
|
+
path={`${app.name.toLowerCase()}/*`}
|
105
105
|
element={
|
106
106
|
<Component
|
107
107
|
loadable={{
|
@@ -138,7 +138,7 @@ export default () => {
|
|
138
138
|
};
|
139
139
|
```
|
140
140
|
|
141
|
-
这里通过 `Route` 组件自定义了 **
|
141
|
+
这里通过 `Route` 组件自定义了 **Table** 的激活路由为 **/table**, **Dashboard** 的激活路由为 **/dashboard**。
|
142
142
|
|
143
143
|
### 集中式路由
|
144
144
|
|
@@ -149,7 +149,7 @@ export default () => {
|
|
149
149
|
然后在主应用中使用 `useModuleApp` 方法获取 `MApp` 组件, 并在主应用渲染 `MApp`。
|
150
150
|
|
151
151
|
```tsx title=主应用:App.tsx
|
152
|
-
import { useModuleApp } from '@modern-js/plugin-runtime';
|
152
|
+
import { useModuleApp } from '@modern-js/plugin-garfish/runtime';
|
153
153
|
|
154
154
|
function App() {
|
155
155
|
const { MApp } = useModuleApps();
|
@@ -162,7 +162,7 @@ function App() {
|
|
162
162
|
}
|
163
163
|
```
|
164
164
|
|
165
|
-
这样启动应用后,访问 `/
|
165
|
+
这样启动应用后,访问 `/table` 路由,会渲染 `Table` 子应用,访问 `/dashboard` 路由,会渲染 `Dashboard` 子应用。
|
166
166
|
|
167
167
|
### 两种模式混用
|
168
168
|
|
@@ -182,7 +182,7 @@ function Loading() {
|
|
182
182
|
|
183
183
|
function App(){
|
184
184
|
return <>
|
185
|
-
<
|
185
|
+
<Table
|
186
186
|
loadable={{
|
187
187
|
loading: Loading,
|
188
188
|
}}
|
@@ -229,7 +229,7 @@ function Loading({ error, pastDelay }) {
|
|
229
229
|
|
230
230
|
function App(){
|
231
231
|
return <>
|
232
|
-
<
|
232
|
+
<Table
|
233
233
|
loadable={{
|
234
234
|
loading: Loading,
|
235
235
|
delay: 300 // 0.3 seconds
|
@@ -265,7 +265,7 @@ function Loading({ error, timeOut, pastDelay }) {
|
|
265
265
|
|
266
266
|
function App(){
|
267
267
|
return <>
|
268
|
-
<
|
268
|
+
<Table
|
269
269
|
loadable={{
|
270
270
|
loading: Loading,
|
271
271
|
timeOut: 10000 // 10s
|