@modern-js/main-doc 2.0.0-beta.0 → 2.0.0-beta.1
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/.turbo/turbo-build.log +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/_category_.json +8 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/build.md +44 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/dev.md +31 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/index.md +12 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/inspect.md +39 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/lint.md +22 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/new.md +59 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/start.md +32 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/test.md +36 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/upgrade.md +21 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/_category_.json +8 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/framework/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/framework/lambda.md +54 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/functions/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/functions/api.md +78 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/functions/app.md +12 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/functions/common.md +10 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/test.md +10 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/html.md +8 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/icon.md +15 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/mock.md +6 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/public.md +28 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/storybook.md +12 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/upload.md +42 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/index.md +7 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/modern-config.md +8 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/server/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/server/index_.md +14 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/server/test.md +10 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/shared.md +6 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/app.md +45 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/index_.md +34 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/pages.md +180 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/stories.md +12 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/test.md +12 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/overview.md +12 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/_category_.json +9 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/app/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/app/define-config.md +60 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/bff/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/bff/hook.md +43 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/bff/use-context.md +36 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/_category_.json +5 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/bootstrap.md +55 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/create-app.md +47 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/use-loader.md +83 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/use-module-apps.md +101 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/use-runtime-context.md +59 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/default-alias.md +25 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/env.md +72 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/index.md +12 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/Provider.md +35 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/auto-actions.md +120 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/connect.md +140 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/create-app.md +73 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/create-store.md +62 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/handle-effect.md +105 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/model_.md +197 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-local-model.md +27 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-model.md +89 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-static-model.md +49 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-store.md +48 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/abstract.md +26 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/hook-api.md +896 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/hook.md +170 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/plugin-api.md +117 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/router/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/router/router.md +492 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/ssr/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/ssr/no-ssr.md +44 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/ssr/pre-render.md +91 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/testing/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/testing/act.md +34 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/testing/cleanup.md +38 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/testing/render.md +72 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/testing/renderApp.md +33 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/utility/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/utility/css-in-js.md +42 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/utility/head.md +39 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/utility/loadable.md +85 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/web-server/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/web-server/hook.md +131 -0
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/web-server/middleware.md +106 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/bff/fetcher.md +28 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/bff/prefix.md +33 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/bff/proxy.md +75 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/dev/asset-prefix.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/dev/hmr.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/dev/https.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/dev/port.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/dev/progress-bar.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/proxy.md +80 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/dev/start-url.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/with-master-app.md +32 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/experiments/lazy-compilation.md +12 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/app-icon.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/crossorigin.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/disable-html-folder.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/favicon-by-entries.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/favicon.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/inject-by-entries.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/inject.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/meta-by-entries.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/meta.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/mount-id.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/template-by-entries.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/template-parameters-by-entries.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/template-parameters.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/template.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/title-by-entries.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/html/title.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/asset-prefix.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/assets-retry.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/charset.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/clean-dist-path.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/convert-to-rem.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/copy.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/css-module-local-ident-name.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/data-uri-limit.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/disable-css-module-extension.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/disable-filename-hash.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/disable-inline-runtime-chunk.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/disable-minimize.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-node-polyfill.md +20 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/disable-source-map.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-ts-checker.md +12 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/dist-path.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/enable-asset-fallback.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/enable-asset-manifest.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/enable-css-module-tsdeclaration.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/enable-inline-scripts.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/enable-inline-styles.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/enable-latest-decorators.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-modern-mode.md +34 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/externals.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/filename.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/legal-comments.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/override-browserslist.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/polyfill.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/output/svg-default-export.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/performance/build-cache.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/performance/bundle-analyze.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/performance/chunk-split.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/performance/print-file-size.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/performance/profile.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/performance/remove-console.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/performance/remove-moment-locale.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/plugins.md +74 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/runtime/intro.md +91 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/runtime/master-app.md +60 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/runtime/router.md +19 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/runtime/state.md +41 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/security/sri.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/server/base-url.md +33 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/server/port.md +18 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/server/public-routes.md +26 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/server/routes.md +91 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/server/ssr-by-entries.md +28 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/server/ssr.md +20 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/source/alias.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/source/compile-js-data-uri.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/config-dir.md +23 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/source/define.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/design-system.md +1150 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/disable-default-entries.md +28 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/enable-async-entry.md +50 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/entries-dir.md +38 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/entries.md +62 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/exclude.md +12 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/source/global-vars.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/source/include.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/source/module-scopes.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/source/pre-entry.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/source/resolve-extension-prefix.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/source/resolve-main-fields.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/testing/transformer.md +18 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/autoprefixer.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/babel.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/css-extract.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/css-loader.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/dev-server.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/esbuild.md +61 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/html-plugin.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/inspector.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/jest.md +39 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/less.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/minify-css.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/postcss.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/pug.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/sass.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/style-loader.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/styled-components.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/tailwindcss.md +47 -0
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/terser.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/ts-checker.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/ts-loader.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/webpack-chain.md +0 -1
- package/en/{configure → docusaurus-plugin-content-docs/current/configure}/app/tools/webpack.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/usage.md +92 -0
- package/en/{tutorials → docusaurus-plugin-content-docs/current/tutorials}/foundations/_category_.json +0 -0
- package/en/{tutorials → docusaurus-plugin-content-docs/current/tutorials}/foundations/basic.md +0 -0
- package/en/{tutorials → docusaurus-plugin-content-docs/current/tutorials}/foundations/introduction.md +0 -0
- package/en/docusaurus-plugin-content-docs/current.json +262 -0
- package/package.json +7 -5
- package/scripts/config.ts +98 -0
- package/scripts/summary.en.json +1 -0
- package/scripts/summary.zh.json +1 -0
- package/scripts/sync.ts +26 -5
- package/zh/apis/app/commands/build.md +2 -2
- package/zh/apis/app/commands/dev.md +1 -1
- package/zh/apis/app/commands/index.md +1 -1
- package/zh/apis/app/commands/lint.md +2 -2
- package/zh/apis/app/commands/new.md +1 -1
- package/zh/apis/app/commands/start.md +1 -1
- package/zh/apis/app/commands/test.md +1 -1
- package/zh/apis/app/commands/upgrade.md +0 -2
- package/zh/apis/app/hooks/api/framework/_category_.json +1 -1
- package/zh/apis/app/hooks/api/framework/lambda.md +8 -33
- package/zh/apis/app/hooks/api/functions/_category_.json +1 -1
- package/zh/apis/app/hooks/api/functions/api.md +29 -2
- package/zh/apis/app/hooks/api/functions/app.md +5 -3
- package/zh/apis/app/hooks/api/functions/common.md +3 -5
- package/zh/apis/app/hooks/api/test.md +2 -4
- package/zh/apis/app/hooks/config/html.md +1 -3
- package/zh/apis/app/hooks/config/icon.md +2 -2
- package/zh/apis/app/hooks/config/mock.md +2 -8
- package/zh/apis/app/hooks/config/public.md +2 -4
- package/zh/apis/app/hooks/config/storybook.md +2 -4
- package/zh/apis/app/hooks/config/upload.md +1 -7
- package/zh/apis/app/hooks/modern-config.md +1 -3
- package/zh/apis/app/hooks/server/index_.md +12 -0
- package/zh/apis/app/hooks/server/test.md +3 -3
- package/zh/apis/app/hooks/shared.md +1 -2
- package/zh/apis/app/hooks/src/app.md +8 -4
- package/zh/apis/app/hooks/src/{index.md → index_.md} +2 -2
- package/zh/apis/app/hooks/src/pages.md +3 -4
- package/zh/apis/app/hooks/src/stories.md +2 -2
- package/zh/apis/app/hooks/src/test.md +1 -1
- package/zh/apis/app/overview.md +1 -1
- package/zh/apis/app/runtime/app/_category_.json +2 -2
- package/zh/apis/app/runtime/app/define-config.md +14 -10
- package/zh/apis/app/runtime/bff/_category_.json +4 -0
- package/zh/apis/app/runtime/bff/hook.md +43 -0
- package/zh/apis/app/runtime/bff/use-context.md +36 -0
- package/zh/apis/app/runtime/core/_category_.json +4 -0
- package/zh/apis/app/runtime/core/bootstrap.md +55 -0
- package/zh/apis/app/runtime/core/create-app.md +47 -0
- package/zh/apis/app/runtime/core/use-loader.md +83 -0
- package/zh/apis/app/runtime/core/use-module-apps.md +101 -0
- package/zh/apis/app/runtime/core/use-runtime-context.md +59 -0
- package/zh/apis/app/runtime/default-alias.md +4 -7
- package/zh/apis/app/runtime/env.md +22 -20
- package/zh/apis/app/runtime/model/Provider.md +6 -8
- package/zh/apis/app/runtime/model/_category_.json +1 -1
- package/zh/apis/app/runtime/model/auto-actions.md +1 -2
- package/zh/apis/app/runtime/model/connect.md +8 -5
- package/zh/apis/app/runtime/model/create-app.md +3 -4
- package/zh/apis/app/runtime/model/create-store.md +5 -3
- package/zh/apis/app/runtime/model/handle-effect.md +5 -5
- package/zh/apis/app/runtime/model/model_.md +3 -3
- package/zh/apis/app/runtime/model/use-local-model.md +2 -2
- package/zh/apis/app/runtime/model/use-model.md +6 -7
- package/zh/apis/app/runtime/model/use-static-model.md +2 -2
- package/zh/apis/app/runtime/model/use-store.md +3 -3
- package/zh/apis/app/runtime/router/_category_.json +4 -0
- package/zh/apis/app/runtime/{container → router}/router.md +0 -0
- package/zh/apis/app/runtime/ssr/_category_.json +4 -0
- package/zh/apis/app/runtime/ssr/no-ssr.md +41 -0
- package/zh/apis/app/runtime/ssr/pre-render.md +91 -0
- package/zh/apis/app/runtime/testing/_category_.json +1 -1
- package/zh/apis/app/runtime/testing/act.md +8 -8
- package/zh/apis/app/runtime/testing/cleanup.md +10 -9
- package/zh/apis/app/runtime/testing/render.md +43 -23
- package/zh/apis/app/runtime/testing/renderApp.md +8 -8
- package/zh/apis/app/runtime/utility/_category_.json +1 -1
- package/zh/apis/app/runtime/utility/css-in-js.md +17 -35
- package/zh/apis/app/runtime/{app → utility}/head.md +6 -10
- package/zh/apis/app/runtime/utility/{loadable/loadable_.md → loadable.md} +29 -56
- package/zh/apis/app/runtime/web-server/_category_.json +1 -1
- package/zh/apis/app/runtime/web-server/hook.md +100 -90
- package/zh/apis/app/runtime/web-server/middleware.md +106 -0
- package/zh/apis/monorepo/commands/bump.md +1 -1
- package/zh/apis/monorepo/commands/change.md +1 -1
- package/zh/apis/monorepo/commands/clear.md +1 -1
- package/zh/apis/monorepo/commands/deploy.md +1 -1
- package/zh/apis/monorepo/commands/gen-release-note.md +1 -1
- package/zh/apis/monorepo/commands/lint.md +1 -1
- package/zh/apis/monorepo/commands/new.md +1 -1
- package/zh/apis/monorepo/commands/pre.md +1 -1
- package/zh/apis/monorepo/commands/release.md +1 -1
- package/zh/configure/app/bff/fetcher.md +1 -2
- package/zh/configure/app/bff/prefix.md +2 -3
- package/zh/configure/app/bff/proxy.md +8 -13
- package/zh/configure/app/dev/asset-prefix.md +0 -1
- package/zh/configure/app/dev/hmr.md +0 -1
- package/zh/configure/app/dev/https.md +0 -1
- package/zh/configure/app/dev/port.md +0 -1
- package/zh/configure/app/dev/progress-bar.md +0 -1
- package/zh/configure/app/dev/proxy.md +2 -3
- package/zh/configure/app/dev/start-url.md +0 -1
- package/zh/configure/app/dev/with-master-app.md +0 -1
- package/zh/configure/app/experiments/lazy-compilation.md +12 -0
- package/zh/configure/app/html/app-icon.md +0 -1
- package/zh/configure/app/html/crossorigin.md +0 -1
- package/zh/configure/app/html/disable-html-folder.md +0 -1
- package/zh/configure/app/html/favicon-by-entries.md +0 -1
- package/zh/configure/app/html/favicon.md +0 -1
- package/zh/configure/app/html/inject-by-entries.md +0 -1
- package/zh/configure/app/html/inject.md +0 -1
- package/zh/configure/app/html/meta-by-entries.md +0 -1
- package/zh/configure/app/html/meta.md +0 -1
- package/zh/configure/app/html/mount-id.md +0 -1
- package/zh/configure/app/html/template-by-entries.md +0 -1
- package/zh/configure/app/html/template-parameters-by-entries.md +0 -1
- package/zh/configure/app/html/template-parameters.md +0 -1
- package/zh/configure/app/html/template.md +0 -1
- package/zh/configure/app/html/title-by-entries.md +0 -1
- package/zh/configure/app/html/title.md +0 -1
- package/zh/configure/app/output/asset-prefix.md +0 -1
- package/zh/configure/app/output/assets-retry.md +0 -1
- package/zh/configure/app/output/charset.md +0 -1
- package/zh/configure/app/output/clean-dist-path.md +0 -1
- package/zh/configure/app/output/convert-to-rem.md +0 -1
- package/zh/configure/app/output/copy.md +0 -1
- package/zh/configure/app/output/css-module-local-ident-name.md +0 -1
- package/zh/configure/app/output/data-uri-limit.md +0 -1
- package/zh/configure/app/output/disable-css-module-extension.md +0 -1
- package/zh/configure/app/output/disable-filename-hash.md +0 -1
- package/zh/configure/app/output/disable-inline-runtime-chunk.md +0 -1
- package/zh/configure/app/output/disable-minimize.md +0 -1
- package/zh/configure/app/output/disable-node-polyfill.md +2 -4
- package/zh/configure/app/output/disable-source-map.md +0 -1
- package/zh/configure/app/output/disable-ts-checker.md +12 -0
- package/zh/configure/app/output/dist-path.md +0 -1
- package/zh/configure/app/output/enable-asset-fallback.md +0 -1
- package/zh/configure/app/output/enable-asset-manifest.md +0 -1
- package/zh/configure/app/output/enable-css-module-tsdeclaration.md +0 -1
- package/zh/configure/app/output/enable-inline-scripts.md +0 -1
- package/zh/configure/app/output/enable-inline-styles.md +0 -1
- package/zh/configure/app/output/enable-latest-decorators.md +0 -1
- package/zh/configure/app/output/enable-modern-mode.md +13 -5
- package/zh/configure/app/output/externals.md +0 -1
- package/zh/configure/app/output/filename.md +0 -1
- package/zh/configure/app/output/legal-comments.md +0 -1
- package/zh/configure/app/output/override-browserslist.md +0 -1
- package/zh/configure/app/output/polyfill.md +0 -1
- package/zh/configure/app/output/svg-default-export.md +0 -1
- package/zh/configure/app/performance/build-cache.md +0 -1
- package/zh/configure/app/performance/bundle-analyze.md +0 -1
- package/zh/configure/app/performance/chunk-split.md +0 -1
- package/zh/configure/app/performance/print-file-size.md +0 -1
- package/zh/configure/app/performance/profile.md +0 -1
- package/zh/configure/app/performance/remove-console.md +0 -1
- package/zh/configure/app/performance/remove-moment-locale.md +0 -1
- package/zh/configure/app/runtime/intro.md +92 -0
- package/zh/configure/app/runtime/master-app.md +8 -21
- package/zh/configure/app/runtime/router.md +4 -38
- package/zh/configure/app/runtime/state.md +10 -13
- package/zh/configure/app/security/sri.md +0 -1
- package/zh/configure/app/server/base-url.md +1 -2
- package/zh/configure/app/server/port.md +1 -2
- package/zh/configure/app/server/public-routes.md +1 -2
- package/zh/configure/app/server/routes.md +4 -5
- package/zh/configure/app/server/ssr-by-entries.md +2 -3
- package/zh/configure/app/server/ssr.md +1 -2
- package/zh/configure/app/source/alias.md +0 -1
- package/zh/configure/app/source/compile-js-data-uri.md +0 -1
- package/zh/configure/app/source/config-dir.md +12 -4
- package/zh/configure/app/source/define.md +0 -1
- package/zh/configure/app/source/design-system.md +14 -24
- package/zh/configure/app/source/disable-default-entries.md +8 -3
- package/zh/configure/app/source/enable-async-entry.md +3 -3
- package/zh/configure/app/source/entries-dir.md +1 -1
- package/zh/configure/app/source/entries.md +16 -9
- package/zh/configure/app/source/exclude.md +12 -0
- package/zh/configure/app/source/global-vars.md +0 -1
- package/zh/configure/app/source/include.md +0 -1
- package/zh/configure/app/source/module-scopes.md +0 -1
- package/zh/configure/app/source/pre-entry.md +0 -1
- package/zh/configure/app/source/resolve-extension-prefix.md +0 -1
- package/zh/configure/app/source/resolve-main-fields.md +0 -1
- package/zh/configure/app/testing/transformer.md +2 -4
- package/zh/configure/app/tools/autoprefixer.md +0 -1
- package/zh/configure/app/tools/babel.md +0 -1
- package/zh/configure/app/tools/css-extract.md +0 -1
- package/zh/configure/app/tools/css-loader.md +0 -1
- package/zh/configure/app/tools/dev-server.md +0 -1
- package/zh/configure/app/tools/esbuild.md +5 -5
- package/zh/configure/app/tools/html-plugin.md +0 -1
- package/zh/configure/app/tools/inspector.md +0 -1
- package/zh/configure/app/tools/jest.md +2 -4
- package/zh/configure/app/tools/less.md +0 -1
- package/zh/configure/app/tools/minify-css.md +0 -1
- package/zh/configure/app/tools/postcss.md +0 -1
- package/zh/configure/app/tools/pug.md +0 -1
- package/zh/configure/app/tools/sass.md +0 -1
- package/zh/configure/app/tools/style-loader.md +0 -1
- package/zh/configure/app/tools/styled-components.md +0 -1
- package/zh/configure/app/tools/terser.md +0 -1
- package/zh/configure/app/tools/ts-checker.md +0 -1
- package/zh/configure/app/tools/ts-loader.md +0 -1
- package/zh/configure/app/tools/webpack-chain.md +0 -1
- package/zh/configure/app/tools/webpack.md +0 -1
- package/zh/configure/app/usage.md +15 -4
- package/zh/guides/advanced-features/bff/bff-server.md +1 -1
- package/zh/guides/advanced-features/bff/frameworks.md +0 -221
- package/zh/guides/advanced-features/code-split.md +1 -1
- package/zh/guides/advanced-features/low-level.md +2 -2
- package/zh/guides/advanced-features/ssg.md +2 -2
- package/zh/guides/advanced-features/ssr.md +4 -4
- package/zh/guides/basic-features/alias.md +1 -1
- package/zh/guides/basic-features/css/postcss.md +1 -1
- package/zh/guides/basic-features/css/tailwindcss.md +2 -2
- package/zh/guides/basic-features/env-vars.md +2 -3
- package/zh/guides/basic-features/proxy.md +2 -2
- package/zh/guides/topic-detail/compile-speed.md +5 -5
- package/zh/guides/topic-detail/generator/_category_.json +4 -0
- package/zh/guides/topic-detail/generator/codesmith/_category_.json +4 -0
- package/zh/guides/topic-detail/generator/codesmith/introduce.md +5 -0
- package/zh/guides/topic-detail/generator/config/_category_.json +4 -0
- package/zh/{configure/generator/introduce.md → guides/topic-detail/generator/config/common.md} +35 -42
- package/zh/{configure/generator → guides/topic-detail/generator/config}/module.md +7 -11
- package/zh/{configure/generator → guides/topic-detail/generator/config}/monorepo.md +4 -4
- package/zh/{configure/generator → guides/topic-detail/generator/config}/mwa.md +11 -45
- package/zh/guides/topic-detail/generator/plugin/_category_.json +4 -0
- package/zh/guides/topic-detail/{generator-plugin → generator/plugin}/abstract.md +0 -0
- package/zh/guides/topic-detail/generator/plugin/api/_category_.json +4 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/file/_category_.json +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/file/addFile.md +1 -1
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/file/addHelper.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/file/addManyFile.md +1 -1
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/file/addPartial.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/file/introduce.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/file/rmDir.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/file/rmFile.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/file/updateJSONFile.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/file/updateModernConfig.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/file/updateTextRawFile.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/git/_category_.json +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/git/gitAddAndCommit.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/git/initGitRepo.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/git/isInGitRepo.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/hook/_category_.json +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/hook/afterForged.md +1 -1
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/hook/onForged.md +1 -1
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/info/_category_.json +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/info/isFileExit.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/info/locale.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/info/readDir.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/input/_category_.json +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/input/addInputAfter.md +14 -6
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/input/addInputBefore.md +14 -6
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/input/setInput.md +2 -2
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/input/setInputValue.md +0 -0
- package/zh/guides/topic-detail/generator/plugin/api/input/type.md +65 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/introduce.md +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/new/_category_.json +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/new/createElement.md +1 -1
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/new/createSubProject.md +1 -1
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/new/enableFunc.md +1 -3
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/new/introduce.md +3 -3
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/npm/_category_.json +0 -0
- package/zh/{apis/generator/plugin → guides/topic-detail/generator/plugin/api}/npm/install.md +0 -0
- package/zh/guides/topic-detail/{generator-plugin → generator/plugin}/develop.md +4 -4
- package/zh/guides/topic-detail/{generator-plugin → generator/plugin}/use.md +0 -0
- package/zh/guides/topic-detail/generator/project.md +117 -0
- package/zh/guides/topic-detail/micro-frontend/debugging.md +5 -5
- package/zh/guides/topic-detail/micro-frontend/route-mode.md +2 -2
- package/zh/guides/troubleshooting/compile.md +3 -3
- package/zh/tutorials/first-app/c01-getting-started/1.4-enable-ssr.md +2 -2
- package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.3-compatibility.md +4 -4
- package/zh/tutorials/first-app/c06-css-and-component/6.4-design-system.md +3 -3
- package/zh/tutorials/first-app/c07-app-entry/7.3-manage-entries-by-hand.md +2 -2
- package/zh/tutorials/first-app/c08-client-side-routing/8.1-code-based-routing.md +1 -1
- package/scripts/gen-config.ts +0 -60
- package/zh/apis/app/hooks/api/framework/app.md +0 -100
- package/zh/apis/app/hooks/server/index.md +0 -14
- package/zh/apis/app/hooks/src/error.md +0 -10
- package/zh/apis/app/hooks/src/eslint.md +0 -9
- package/zh/apis/app/runtime/app/bootstrap.md +0 -83
- package/zh/apis/app/runtime/app/create-app.md +0 -47
- package/zh/apis/app/runtime/app/no-ssr.md +0 -41
- package/zh/apis/app/runtime/app/pre-render.md +0 -77
- package/zh/apis/app/runtime/app/use-module-app.md +0 -60
- package/zh/apis/app/runtime/app/use-module-apps.md +0 -64
- package/zh/apis/app/runtime/app/use-runtime-context.md +0 -39
- package/zh/apis/app/runtime/bff-server/_category_.json +0 -4
- package/zh/apis/app/runtime/bff-server/after-lambda-registed.md +0 -35
- package/zh/apis/app/runtime/bff-server/hook.md +0 -120
- package/zh/apis/app/runtime/bff-server/use-context.md +0 -70
- package/zh/apis/app/runtime/container/_category_.json +0 -4
- package/zh/apis/app/runtime/container/use-loader.md +0 -64
- package/zh/apis/app/runtime/utility/loadable/_category_.json +0 -4
- package/zh/apis/app/runtime/utility/loadable/lazy.md +0 -29
- package/zh/apis/app/runtime/utility/loadable/loadable-component.md +0 -61
- package/zh/apis/app/runtime/utility/loadable/loadable-library.md +0 -67
- package/zh/apis/generator/plugin/_category_.json +0 -4
- package/zh/apis/generator/plugin/input/addOptionAfter.md +0 -45
- package/zh/apis/generator/plugin/input/addOptionBefore.md +0 -45
- package/zh/apis/generator/plugin/input/type.md +0 -101
- package/zh/guides/topic-detail/generator-plugin/_category_.json +0 -4
@@ -0,0 +1,492 @@
|
|
1
|
+
---
|
2
|
+
title: router
|
3
|
+
sidebar_position: 1
|
4
|
+
---
|
5
|
+
|
6
|
+
:::info 补充信息
|
7
|
+
基于 [react-router](https://reactrouter.com/web/guides/start) 的路由解决方案。
|
8
|
+
:::
|
9
|
+
|
10
|
+
:::caution 注意
|
11
|
+
使用该 API 前,请确认没有禁用 [router 插件](#)。
|
12
|
+
:::
|
13
|
+
|
14
|
+
## hooks
|
15
|
+
|
16
|
+
### useHistory
|
17
|
+
|
18
|
+
```ts
|
19
|
+
function useHistory<HistoryLocationState = H.LocationState>(): H.History<HistoryLocationState>;
|
20
|
+
```
|
21
|
+
|
22
|
+
用于获取 `history` 实例。
|
23
|
+
|
24
|
+
```tsx
|
25
|
+
import { useHistory } from "@modern-js/runtime/router";
|
26
|
+
|
27
|
+
export function HomeButton() {
|
28
|
+
let history = useHistory();
|
29
|
+
|
30
|
+
function handleClick() {
|
31
|
+
history.push("/home");
|
32
|
+
}
|
33
|
+
|
34
|
+
return (
|
35
|
+
<button type="button" onClick={handleClick}>
|
36
|
+
Go home
|
37
|
+
</button>
|
38
|
+
);
|
39
|
+
}
|
40
|
+
```
|
41
|
+
|
42
|
+
### useLocation
|
43
|
+
|
44
|
+
```ts
|
45
|
+
function useLocation<S = H.LocationState>(): H.Location<S>;
|
46
|
+
```
|
47
|
+
|
48
|
+
`useLocation` 返回当前 url 对应的 [location](https://reactrouter.com/web/api/location) 对象。每当路由更新的时候,都会拿到一个新的 `location` 对象。
|
49
|
+
|
50
|
+
```ts
|
51
|
+
import React from "react";
|
52
|
+
import { bootstrap, createApp } from '@modern-js/runtime';
|
53
|
+
import { router } from '@modern-js/runtime/plugins';
|
54
|
+
import {
|
55
|
+
BrowserRouter as Router,
|
56
|
+
Switch,
|
57
|
+
useLocation
|
58
|
+
} from "@modern-js/runtime/router";
|
59
|
+
|
60
|
+
function usePageViews() {
|
61
|
+
let location = useLocation();
|
62
|
+
React.useEffect(() => {
|
63
|
+
ga.send(["pageview", location.pathname]);
|
64
|
+
}, [location]);
|
65
|
+
}
|
66
|
+
|
67
|
+
function App() {
|
68
|
+
usePageViews();
|
69
|
+
return <Switch>...</Switch>;
|
70
|
+
}
|
71
|
+
```
|
72
|
+
|
73
|
+
### useParams
|
74
|
+
|
75
|
+
```ts
|
76
|
+
function useParams<
|
77
|
+
Params extends {
|
78
|
+
[K in keyof Params]?: string
|
79
|
+
} = {}
|
80
|
+
>(): Params;
|
81
|
+
```
|
82
|
+
|
83
|
+
`useParams` 返回一个 key/value 的键值对表示路由中的参数信息。它等同于 `<Route >` 组件中的 `match.params` 值。
|
84
|
+
|
85
|
+
```tsx
|
86
|
+
import React from "react";
|
87
|
+
import {
|
88
|
+
Switch,
|
89
|
+
Route,
|
90
|
+
useParams
|
91
|
+
} from "@modern-js/runtime/router";
|
92
|
+
|
93
|
+
function BlogPost() {
|
94
|
+
const { slug } = useParams();
|
95
|
+
return <div>Now showing post {slug}</div>;
|
96
|
+
}
|
97
|
+
|
98
|
+
function App() {
|
99
|
+
return <Switch>
|
100
|
+
<Route exact path="/">
|
101
|
+
<div>home</div>
|
102
|
+
</Route>
|
103
|
+
<Route path="/blog/:slug">
|
104
|
+
<BlogPost />
|
105
|
+
</Route>
|
106
|
+
</Switch>
|
107
|
+
}
|
108
|
+
```
|
109
|
+
|
110
|
+
### useRouteMatch
|
111
|
+
|
112
|
+
```ts
|
113
|
+
function useRouteMatch<
|
114
|
+
Params extends { [K in keyof Params]?: string } = {}
|
115
|
+
>(): match<Params>;
|
116
|
+
|
117
|
+
function useRouteMatch<
|
118
|
+
Params extends { [K in keyof Params]?: string } = {}
|
119
|
+
>(
|
120
|
+
path: string | string[] | RouteProps,
|
121
|
+
): match<Params> | null;
|
122
|
+
```
|
123
|
+
|
124
|
+
`useRouteMatch` 和 `<Route />` 一样是对路由进行匹配,但无须去渲染 `<Route />` 组件,便能获取到当前匹配结果。
|
125
|
+
|
126
|
+
## 组件
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
### Link
|
131
|
+
|
132
|
+
```ts
|
133
|
+
interface Link<S = H.LocationState>
|
134
|
+
extends React.ForwardRefExoticComponent<
|
135
|
+
React.PropsWithoutRef<LinkProps<S>> & React.RefAttributes<HTMLAnchorElement>
|
136
|
+
> {}
|
137
|
+
```
|
138
|
+
|
139
|
+
可以使用 `Link` 组件进行路由跳转。
|
140
|
+
|
141
|
+
```ts
|
142
|
+
<Link to="/about">About</Link>
|
143
|
+
```
|
144
|
+
|
145
|
+
#### LinkProps
|
146
|
+
|
147
|
+
**to**
|
148
|
+
|
149
|
+
类型: `string | object | function`
|
150
|
+
|
151
|
+
`string`
|
152
|
+
|
153
|
+
```ts
|
154
|
+
<Link to="/courses?sort=name" />
|
155
|
+
```
|
156
|
+
|
157
|
+
`object`
|
158
|
+
|
159
|
+
```tsx
|
160
|
+
<Link
|
161
|
+
to={{
|
162
|
+
pathname: "/courses",
|
163
|
+
search: "?sort=name",
|
164
|
+
hash: "#the-hash",
|
165
|
+
state: { fromDashboard: true }
|
166
|
+
}}
|
167
|
+
/>
|
168
|
+
```
|
169
|
+
|
170
|
+
`function`
|
171
|
+
|
172
|
+
```tsx
|
173
|
+
<Link to={location => ({ ...location, pathname: "/courses" })} />
|
174
|
+
|
175
|
+
<Link to={location => `${location.pathname}?sort=name`} />
|
176
|
+
```
|
177
|
+
|
178
|
+
**replace**
|
179
|
+
|
180
|
+
类型: `boolean`
|
181
|
+
|
182
|
+
当设置为 `true` 时,在跳转的时候替换掉 history 栈中的栈顶路由,而不是添加一个新路由。
|
183
|
+
|
184
|
+
**component**
|
185
|
+
|
186
|
+
类型: `Component`
|
187
|
+
|
188
|
+
如果你想自定义你自己的路由跳转的组件,可以通过传入 `component` 来实现。
|
189
|
+
|
190
|
+
```tsx
|
191
|
+
simply do so by passing it through the component prop.const FancyLink = React.forwardRef((props, ref) => (
|
192
|
+
<a ref={ref} {...props}>💅 {props.children}</a>
|
193
|
+
))
|
194
|
+
|
195
|
+
<Link to="/" component={FancyLink} />
|
196
|
+
```
|
197
|
+
|
198
|
+
### NavLink
|
199
|
+
|
200
|
+
```ts
|
201
|
+
interface NavLink<S = H.LocationState>
|
202
|
+
extends React.ForwardRefExoticComponent<
|
203
|
+
React.PropsWithoutRef<NavLinkProps<S>> & React.RefAttributes<HTMLAnchorElement>
|
204
|
+
> {}
|
205
|
+
```
|
206
|
+
|
207
|
+
`NavLink` 是一种特殊的 [Link](#link) 组件,当 `NavLink` 对应路由匹配到当前 `url`, 会给 `NavLink` 所渲染的元素添加一些额外的样式。
|
208
|
+
|
209
|
+
|
210
|
+
#### NavLinkProps
|
211
|
+
|
212
|
+
**activeClassName**
|
213
|
+
|
214
|
+
类型: `string`
|
215
|
+
|
216
|
+
设置路由匹配时额外 class。
|
217
|
+
|
218
|
+
```tsx
|
219
|
+
<NavLink to="/faq" activeClassName="selected">
|
220
|
+
FAQs
|
221
|
+
</NavLink>
|
222
|
+
```
|
223
|
+
|
224
|
+
**activeStyle**
|
225
|
+
|
226
|
+
类型: `object`
|
227
|
+
|
228
|
+
设置路由匹配时额外的样式。
|
229
|
+
|
230
|
+
```tsx
|
231
|
+
<NavLink
|
232
|
+
to="/faq"
|
233
|
+
activeStyle={{
|
234
|
+
fontWeight: "bold",
|
235
|
+
color: "red"
|
236
|
+
}}
|
237
|
+
>
|
238
|
+
FAQs
|
239
|
+
</NavLink>
|
240
|
+
```
|
241
|
+
|
242
|
+
**exact**
|
243
|
+
|
244
|
+
类型: `boolean`
|
245
|
+
|
246
|
+
|
247
|
+
**strict**
|
248
|
+
|
249
|
+
类型: `boolean`
|
250
|
+
|
251
|
+
**isActive**
|
252
|
+
|
253
|
+
类型: `function`
|
254
|
+
|
255
|
+
如果你想自定义当前 Link 是否激活的逻辑,可以使用 `isActive`。
|
256
|
+
|
257
|
+
```tsx
|
258
|
+
<NavLink
|
259
|
+
to="/events/123"
|
260
|
+
isActive={(match, location) => {
|
261
|
+
if (!match) {
|
262
|
+
return false;
|
263
|
+
}
|
264
|
+
|
265
|
+
// only consider an event active if its event id is an odd number
|
266
|
+
const eventID = parseInt(match.params.eventID);
|
267
|
+
return !isNaN(eventID) && eventID % 2 === 1;
|
268
|
+
}}
|
269
|
+
>
|
270
|
+
Event 123
|
271
|
+
</NavLink>
|
272
|
+
```
|
273
|
+
|
274
|
+
**location**
|
275
|
+
|
276
|
+
类型: `object`
|
277
|
+
|
278
|
+
`NavLink` 默认会和当前的 `history.location` 进行匹配,判断是否处于激活状态。如果你想指定要匹配的 `location` 对象,可以使用该参数。
|
279
|
+
|
280
|
+
**area-current**
|
281
|
+
|
282
|
+
类型: `string`
|
283
|
+
|
284
|
+
参考 [aria-current](https://www.w3.org/TR/wai-aria-1.1/#aria-current)
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
### Prompt
|
289
|
+
|
290
|
+
```ts
|
291
|
+
interface PromptProps {
|
292
|
+
message: string | ((location: H.Location, action: H.Action) => string | boolean);
|
293
|
+
when?: boolean;
|
294
|
+
}
|
295
|
+
|
296
|
+
class Prompt extends React.Component<PromptProps, any> {}
|
297
|
+
```
|
298
|
+
|
299
|
+
`Prompt` 组件可用于在页面跳转前,进行二次确认是否跳转。
|
300
|
+
|
301
|
+
```tsx
|
302
|
+
<Prompt
|
303
|
+
when={formIsHalfFilledOut}
|
304
|
+
message="Are you sure you want to leave?"
|
305
|
+
/>
|
306
|
+
```
|
307
|
+
|
308
|
+
#### PromptProps
|
309
|
+
|
310
|
+
**message**
|
311
|
+
|
312
|
+
类型: `string` | `function`
|
313
|
+
|
314
|
+
在页面跳转前的二次确认提示信息,支持传入函数形式。
|
315
|
+
|
316
|
+
```tsx
|
317
|
+
<Prompt
|
318
|
+
message={(location, action) => {
|
319
|
+
if (action === 'POP') {
|
320
|
+
console.log("Backing up...")
|
321
|
+
}
|
322
|
+
|
323
|
+
return location.pathname.startsWith("/app")
|
324
|
+
? true
|
325
|
+
: `Are you sure you want to go to ${location.pathname}?`
|
326
|
+
}}
|
327
|
+
/>
|
328
|
+
```
|
329
|
+
|
330
|
+
**when**
|
331
|
+
|
332
|
+
类型: `boolean`
|
333
|
+
|
334
|
+
当 `when` 为 `true` 时,才会在页面跳转前展示二次确认提示。
|
335
|
+
|
336
|
+
|
337
|
+
### Route
|
338
|
+
|
339
|
+
```ts
|
340
|
+
interface RouteProps<
|
341
|
+
Path extends string = string,
|
342
|
+
Params extends { [K: string]: string | undefined } = ExtractRouteParams<Path, string>
|
343
|
+
> {
|
344
|
+
location?: H.Location;
|
345
|
+
component?: React.ComponentType<RouteComponentProps<any>> | React.ComponentType<any>;
|
346
|
+
render?: (props: RouteComponentProps<Params>) => React.ReactNode;
|
347
|
+
children?: ((props: RouteChildrenProps<Params>) => React.ReactNode) | React.ReactNode;
|
348
|
+
path?: Path | Path[];
|
349
|
+
exact?: boolean;
|
350
|
+
sensitive?: boolean;
|
351
|
+
strict?: boolean;
|
352
|
+
}
|
353
|
+
|
354
|
+
class Route<T extends {} = {}, Path extends string = string> extends React.Component<
|
355
|
+
RouteProps<Path> & OmitNative<T, keyof RouteProps>,
|
356
|
+
any
|
357
|
+
> {}
|
358
|
+
```
|
359
|
+
|
360
|
+
`Route` 组件用于定义路由。
|
361
|
+
|
362
|
+
#### component
|
363
|
+
|
364
|
+
类型: `React.ComponentType`
|
365
|
+
|
366
|
+
当路由匹配成功,会渲染传入 `component` 的组件。
|
367
|
+
|
368
|
+
```tsx
|
369
|
+
import React from "react";
|
370
|
+
import { Route } from "@modern-js/runtime/router";
|
371
|
+
|
372
|
+
// All route props (match, location and history) are available to User
|
373
|
+
function User(props) {
|
374
|
+
return <h1>Hello {props.match.params.username}!</h1>;
|
375
|
+
}
|
376
|
+
|
377
|
+
function App() {
|
378
|
+
return <Route path="/user/:username" component={User} />;
|
379
|
+
}
|
380
|
+
```
|
381
|
+
|
382
|
+
:::tip 提示
|
383
|
+
如果 component 是一个 inline function,如 `<Route path="/user/:username" component={() => 'hello'} />`,因为每次 rerender 的时候,component 都会是一个新的 `type`,所以 component 组件会先 unmount,再 mount。我们需要避免这种写法,或者使用 render 代替 component。
|
384
|
+
:::
|
385
|
+
|
386
|
+
#### render
|
387
|
+
|
388
|
+
类型: `(props: RouteComponentProps<Params>) => React.ReactNode`
|
389
|
+
|
390
|
+
允许使用 `inline function` 进行渲染,同时不会有 `component` remounting 的问题。
|
391
|
+
|
392
|
+
```tsx
|
393
|
+
import React from "react";
|
394
|
+
import { Route } from "@modern-js/runtime/router";
|
395
|
+
|
396
|
+
function App() {
|
397
|
+
<Route path="/home" render={() => <div>Home</div>} />
|
398
|
+
}
|
399
|
+
```
|
400
|
+
|
401
|
+
:::info
|
402
|
+
component 的优先级高于 render。
|
403
|
+
:::
|
404
|
+
|
405
|
+
#### children
|
406
|
+
|
407
|
+
类型: `((props: RouteChildrenProps<Params>) => React.ReactNode) | React.ReactNode`
|
408
|
+
|
409
|
+
如果在路由匹配或不匹配的情况下,都需要渲染一些内容,那么可以使用 `children` 参数。
|
410
|
+
|
411
|
+
```tsx
|
412
|
+
function ListItemLink({ to, ...rest }) {
|
413
|
+
return (
|
414
|
+
<Route
|
415
|
+
path={to}
|
416
|
+
children={({ match }) => (
|
417
|
+
<li className={match ? "active" : ""}>
|
418
|
+
<Link to={to} {...rest} />
|
419
|
+
</li>
|
420
|
+
)}
|
421
|
+
/>
|
422
|
+
);
|
423
|
+
}
|
424
|
+
|
425
|
+
function App() {
|
426
|
+
return <ul>
|
427
|
+
<ListItemLink to="/somewhere" />
|
428
|
+
<ListItemLink to="/somewhere-else" />
|
429
|
+
</ul>;
|
430
|
+
}
|
431
|
+
```
|
432
|
+
|
433
|
+
#### path
|
434
|
+
|
435
|
+
类型: `string | string[]`
|
436
|
+
|
437
|
+
符合 [path-to-regexp@^1.7.0](https://github.com/pillarjs/path-to-regexp/tree/v1.7.0) 匹配规则的 url 字符串或数组。
|
438
|
+
|
439
|
+
```tsx
|
440
|
+
<Route path="/users/:id">
|
441
|
+
<User />
|
442
|
+
</Route>
|
443
|
+
|
444
|
+
<Route path={["/users/:id", "/profile/:id"]}>
|
445
|
+
<User />
|
446
|
+
</Route>
|
447
|
+
```
|
448
|
+
|
449
|
+
#### exact
|
450
|
+
|
451
|
+
类型: `boolean`
|
452
|
+
|
453
|
+
默认值: `false`
|
454
|
+
|
455
|
+
当 `exact` 值为 `true` 时,会进行准确匹配。
|
456
|
+
|
457
|
+
| path | location.pathname | exact | matches? |
|
458
|
+
| - | - | - | - |
|
459
|
+
| /one | /one/two | true | no |
|
460
|
+
| /one | /one/two | false | yes |
|
461
|
+
|
462
|
+
|
463
|
+
#### strict
|
464
|
+
|
465
|
+
类型: `boolean`
|
466
|
+
|
467
|
+
默认值: `false`
|
468
|
+
|
469
|
+
当 `strict` 值为 `true` 时,会进行严格匹配。若 `path` 以 '/' 结尾,那么 `location.pathname` 也需要以 '/' 结尾,才能匹配。
|
470
|
+
|
471
|
+
| path | location.pathname | matches? |
|
472
|
+
| - | - | - |
|
473
|
+
| /one/ | /one | no |
|
474
|
+
| /one/ | /one/ | yes |
|
475
|
+
| /one/| /one/two | yes |
|
476
|
+
|
477
|
+
#### sensitive
|
478
|
+
|
479
|
+
类型: `boolean`
|
480
|
+
|
481
|
+
默认值: `false`
|
482
|
+
|
483
|
+
当 `sensitive` 设置为 `true`,则 path 大小写不敏感。
|
484
|
+
|
485
|
+
#### location
|
486
|
+
|
487
|
+
类型: `object`
|
488
|
+
|
489
|
+
## 更多底层 API
|
490
|
+
|
491
|
+
若想要了解更多的底层 API 信息,可至 [react-router 官网](https://reactrouter.com/web/guides/start) 查看。
|
492
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
---
|
2
|
+
title: NoSSR
|
3
|
+
---
|
4
|
+
|
5
|
+
The content wrapped by NoSSR will not be rendered at the server, nor will it be rendered during the client side hydrate. it will only be rendered immediately after the entire app is rendered.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```tsx
|
10
|
+
import { NoSSR } from '@modern-js/runtime';
|
11
|
+
|
12
|
+
export default () => (
|
13
|
+
<NoSSR>
|
14
|
+
...
|
15
|
+
</NoSSR>
|
16
|
+
)
|
17
|
+
```
|
18
|
+
|
19
|
+
## Example
|
20
|
+
|
21
|
+
In the following code, the `Time` component is used to display the current time. Since the time obtained by server-side rendering and client side hydrate are diff, React will throw an exception. For this case, you can use `NoSSR` to optimize:
|
22
|
+
|
23
|
+
```tsx
|
24
|
+
import { NoSSR } from '@modern-js/runtime';
|
25
|
+
|
26
|
+
function Time() {
|
27
|
+
return (
|
28
|
+
<NoSSR>
|
29
|
+
<div>Time: {Date.now()}</div>
|
30
|
+
</NoSSR>
|
31
|
+
);
|
32
|
+
}
|
33
|
+
```
|
34
|
+
|
35
|
+
## Scene
|
36
|
+
|
37
|
+
In CSR, it is often necessary to render different content according to the browser UA, or a parameter of the current page URL. If the application switches directly to SSR at this time, it is very likely that the results will not meet the expectations.
|
38
|
+
|
39
|
+
Modern.js provides complete browser side information in the SSR context, which can be used to determine the rendering result of the component on the server side.
|
40
|
+
|
41
|
+
Even so, if there is too much logic in the application, or the developer wants to use the context later, or does not want some content to be rendered at the server side. developer can use the NoSSR component to exclude this part from server-side rendering.
|
42
|
+
|
43
|
+
|
44
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
---
|
2
|
+
title: PreRender
|
3
|
+
---
|
4
|
+
|
5
|
+
A Helmet-like HOC without content implements SPA routing-level caching, manner without additional configuration.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```tsx
|
10
|
+
import { PreRender } from '@modern-js/runtime/ssr';
|
11
|
+
|
12
|
+
export default () => (
|
13
|
+
<>
|
14
|
+
<PreRender interval={5} />
|
15
|
+
</>
|
16
|
+
)
|
17
|
+
```
|
18
|
+
|
19
|
+
## Function Signature
|
20
|
+
|
21
|
+
The `PreRender` provides a set of configuration for controlling caching rules, expiration times, caching algorithms, and more.
|
22
|
+
|
23
|
+
```tsx
|
24
|
+
type Props {
|
25
|
+
interval: number;
|
26
|
+
staleLimit: number;
|
27
|
+
level: number;
|
28
|
+
include: { header?: string[], query?: string[] };
|
29
|
+
matches: { header?: Record<string, any>, query?: Record<string, any> }
|
30
|
+
}
|
31
|
+
|
32
|
+
function PreRender(props: Props): React.Component
|
33
|
+
```
|
34
|
+
|
35
|
+
### Input
|
36
|
+
|
37
|
+
- `interval`: set the time the cache keep fresh,seconds. During this time, the cache will be used directly and not invoke asynchronous rendering.
|
38
|
+
- `staleLimit`: sets the time when the cache is completely expired,seconds。During this time, The cache can be returned and asynchronous rendering will be invoke, otherwise must wait for the re-rendered result.
|
39
|
+
- `level`: sets the calculation rule level for the cache identity, usually used with `includes` and `matches`. The default value is `0`.
|
40
|
+
|
41
|
+
```bash
|
42
|
+
0: pathname
|
43
|
+
1: pathname + querystring
|
44
|
+
2: pathname + headers
|
45
|
+
3: pathname + querystring + headers
|
46
|
+
```
|
47
|
+
|
48
|
+
- `includes`: sets the content that needs to be included in the cache identifier, used when the `level` is not `0`. The default value is `null`.
|
49
|
+
- `matches`: sets the rewriting rule for the value of query or header in cache identity, usually used in cache category, supports regular expressions. The default value is `null`.
|
50
|
+
|
51
|
+
## Example
|
52
|
+
|
53
|
+
```tsx
|
54
|
+
import { PreRender } from '@modern-js/runtime/ssr';
|
55
|
+
|
56
|
+
export default function App() {
|
57
|
+
return (
|
58
|
+
<>
|
59
|
+
<PreRender interval={10} />
|
60
|
+
<div>Hello Modern</div>
|
61
|
+
</>
|
62
|
+
)
|
63
|
+
}
|
64
|
+
```
|
65
|
+
|
66
|
+
The following example shows how to add the parameters in the query and header into the cache identifier calculation:
|
67
|
+
|
68
|
+
```tsx
|
69
|
+
/* calculate cache identifier using channel in query and language in header */
|
70
|
+
<PreRender interval={10} level={2} includes={{
|
71
|
+
query: ["channel"],
|
72
|
+
header: ["language"]
|
73
|
+
}} />
|
74
|
+
```
|
75
|
+
|
76
|
+
The following example shows how not to let the test channel affect the online cache:
|
77
|
+
|
78
|
+
```tsx
|
79
|
+
/* rewrite the channel value starting with test_ in the query as "testChannel", otherwise rewrite it as "otherChannel" */
|
80
|
+
<PreRender interval={10} level={2} includes={{
|
81
|
+
query: ["channel"],
|
82
|
+
header: ["language"]
|
83
|
+
}} matches={{
|
84
|
+
query: {
|
85
|
+
channel: {
|
86
|
+
"testChannel", "^test_",
|
87
|
+
"otherChannel", ".*"
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}} />
|
91
|
+
```
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
title: act
|
3
|
+
---
|
4
|
+
|
5
|
+
Used to ensure that behaviors such as rendering, events, data fetching, etc. have been applied to the DOM.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```ts
|
10
|
+
import { act } from '@modern-js/runtime/testing';
|
11
|
+
```
|
12
|
+
|
13
|
+
## Function Signature
|
14
|
+
|
15
|
+
`act` is the same as [react-dom/test-utils act function](https://reactjs.org/docs/testing-recipes.html#act).
|
16
|
+
|
17
|
+
## Example
|
18
|
+
|
19
|
+
```tsx
|
20
|
+
import ReactDOM from 'react-dom';
|
21
|
+
import { act } from '@modern-js/runtime/testing';
|
22
|
+
import { Foo } from '@/components/Foo';
|
23
|
+
|
24
|
+
describe('test act', () => {
|
25
|
+
it('it should be foo', () => {
|
26
|
+
const el = document.createElement('div');
|
27
|
+
act(() => {
|
28
|
+
ReactDOM.render(<Foo />, el);
|
29
|
+
});
|
30
|
+
|
31
|
+
expect(el.innerHTML).toBe('<div>Foo</div>');
|
32
|
+
});
|
33
|
+
});
|
34
|
+
```
|
@@ -0,0 +1,38 @@
|
|
1
|
+
---
|
2
|
+
title: cleanup
|
3
|
+
sidebar_position: 3
|
4
|
+
---
|
5
|
+
|
6
|
+
Used to uninstall all currently rendered components.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
```ts
|
11
|
+
import { cleanup } from '@modenr-js/runtime/testing';
|
12
|
+
```
|
13
|
+
|
14
|
+
## Function Signature
|
15
|
+
|
16
|
+
`function cleanup(): void`
|
17
|
+
|
18
|
+
## Example
|
19
|
+
|
20
|
+
:::info
|
21
|
+
Note that if you are using a testing framework that supports afterEach and it is injected into your testing environment (such as mocha, Jest, and Jasmine), **will execute `cleanup`** in the afterEach hook by default. Otherwise, you will need to do manual cleanup after each test.
|
22
|
+
:::
|
23
|
+
|
24
|
+
For example, if you use the [ava](https://github.com/avajs/ava) test framework, then you need to use the `test.after Each` hook like this.
|
25
|
+
|
26
|
+
```tsx
|
27
|
+
import { cleanup, render } from '@modern-js/runtime/testing';
|
28
|
+
import test from 'ava';
|
29
|
+
|
30
|
+
test.afterEach(cleanup);
|
31
|
+
|
32
|
+
test('renders into document', () => {
|
33
|
+
render(<div />);
|
34
|
+
// ...
|
35
|
+
});
|
36
|
+
|
37
|
+
// ... more tests ...
|
38
|
+
```
|