@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.98 → 3.8.1-ultramodern.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.
Files changed (334) hide show
  1. package/bin/modern-bundle-docs.js +7 -0
  2. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +5 -1
  3. package/dist/cjs/builder/generator/getBuilderEnvironments.js +80 -11
  4. package/dist/cjs/bundleDocs.js +114 -0
  5. package/dist/cjs/commands/build.js +2 -1
  6. package/dist/cjs/commands/deploy.js +4 -2
  7. package/dist/cjs/commands/index.js +0 -4
  8. package/dist/cjs/config/default.js +2 -0
  9. package/dist/cjs/index.js +56 -15
  10. package/dist/cjs/plugins/analyze/index.js +2 -2
  11. package/dist/cjs/plugins/analyze/utils.js +3 -2
  12. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +1 -1
  13. package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.js +94 -18
  14. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +1 -0
  15. package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-worker-mf-ssr-runtime-plugin.mjs +14 -0
  16. package/dist/cjs/plugins/initialize/index.js +4 -3
  17. package/dist/cjs/plugins/serverBuild.js +3 -2
  18. package/dist/cjs/ultramodern-release-envelope/framework-output.js +109 -57
  19. package/dist/esm/builder/generator/createBuilderProviderConfig.mjs +5 -1
  20. package/dist/esm/builder/generator/getBuilderEnvironments.mjs +70 -10
  21. package/dist/esm/bundleDocs.mjs +62 -0
  22. package/dist/esm/commands/build.mjs +2 -1
  23. package/dist/esm/commands/deploy.mjs +4 -2
  24. package/dist/esm/commands/index.mjs +0 -4
  25. package/dist/esm/config/default.mjs +2 -0
  26. package/dist/esm/index.mjs +15 -1
  27. package/dist/esm/plugins/analyze/index.mjs +2 -2
  28. package/dist/esm/plugins/analyze/utils.mjs +3 -2
  29. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +1 -1
  30. package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +93 -18
  31. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +1 -0
  32. package/dist/esm/plugins/deploy/platforms/templates/cloudflare-worker-mf-ssr-runtime-plugin.mjs +14 -0
  33. package/dist/esm/plugins/initialize/index.mjs +4 -3
  34. package/dist/esm/plugins/serverBuild.mjs +3 -2
  35. package/dist/esm/ultramodern-release-envelope/framework-output.mjs +107 -58
  36. package/dist/esm-node/builder/generator/createBuilderProviderConfig.mjs +5 -1
  37. package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +70 -10
  38. package/dist/esm-node/bundleDocs.mjs +63 -0
  39. package/dist/esm-node/commands/build.mjs +2 -1
  40. package/dist/esm-node/commands/deploy.mjs +4 -2
  41. package/dist/esm-node/commands/index.mjs +0 -4
  42. package/dist/esm-node/config/default.mjs +2 -0
  43. package/dist/esm-node/index.mjs +15 -1
  44. package/dist/esm-node/plugins/analyze/index.mjs +2 -2
  45. package/dist/esm-node/plugins/analyze/utils.mjs +3 -2
  46. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +1 -1
  47. package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.mjs +93 -18
  48. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.mjs +1 -0
  49. package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-worker-mf-ssr-runtime-plugin.mjs +14 -0
  50. package/dist/esm-node/plugins/initialize/index.mjs +4 -3
  51. package/dist/esm-node/plugins/serverBuild.mjs +3 -2
  52. package/dist/esm-node/ultramodern-release-envelope/framework-output.mjs +107 -58
  53. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +29 -0
  54. package/dist/types/bundleDocs.d.ts +20 -0
  55. package/dist/types/commands/deploy.d.ts +2 -1
  56. package/dist/types/index.d.ts +4 -1
  57. package/dist/types/plugins/analyze/utils.d.ts +1 -1
  58. package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/worker-bundles.d.ts +1 -1
  59. package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.001-bootstrap-security.d.mts +1 -1
  60. package/dist/types/plugins/deploy/platforms/templates/cloudflare-worker-mf-ssr-runtime-plugin.d.mts +13 -0
  61. package/dist/types/types/config/dev.d.ts +6 -0
  62. package/dist/types/ultramodern-release-envelope/framework-output.d.ts +1 -0
  63. package/docs/apis/app/commands.md +231 -0
  64. package/docs/apis/app/hooks/api/lambda.md +9 -0
  65. package/docs/apis/app/hooks/config/favicon.md +24 -0
  66. package/docs/apis/app/hooks/config/html.md +5 -0
  67. package/docs/apis/app/hooks/config/icon.md +24 -0
  68. package/docs/apis/app/hooks/config/mock.md +6 -0
  69. package/docs/apis/app/hooks/config/public.md +26 -0
  70. package/docs/apis/app/hooks/config/upload.md +50 -0
  71. package/docs/apis/app/hooks/modern-config.md +5 -0
  72. package/docs/apis/app/hooks/server/server.md +5 -0
  73. package/docs/apis/app/hooks/shared.md +3 -0
  74. package/docs/apis/app/hooks/src/app.md +30 -0
  75. package/docs/apis/app/hooks/src/entry.md +34 -0
  76. package/docs/apis/app/hooks/src/entry.server.md +51 -0
  77. package/docs/apis/app/hooks/src/modern.runtime.md +5 -0
  78. package/docs/apis/app/hooks/src/routes.md +86 -0
  79. package/docs/apis/app/hooks/src/server.md +3 -0
  80. package/docs/apis/app/runtime/bff/use-backend-context.md +27 -0
  81. package/docs/apis/app/runtime/core/create-root.md +19 -0
  82. package/docs/apis/app/runtime/core/render.md +39 -0
  83. package/docs/apis/app/runtime/core/runtime-context.md +156 -0
  84. package/docs/apis/app/runtime/router/router.md +283 -0
  85. package/docs/apis/app/runtime/ssr/no-ssr.md +35 -0
  86. package/docs/apis/app/runtime/ssr/renderStreaming.md +67 -0
  87. package/docs/apis/app/runtime/ssr/renderString.md +60 -0
  88. package/docs/apis/app/runtime/ssr/requestHandler.md +44 -0
  89. package/docs/apis/app/runtime/utility/css-in-js.md +40 -0
  90. package/docs/apis/app/runtime/utility/head.md +35 -0
  91. package/docs/apis/app/runtime/utility/loadable.md +82 -0
  92. package/docs/community/blog/2022-0708-updates.md +91 -0
  93. package/docs/community/blog/2022-0910-updates.md +76 -0
  94. package/docs/community/blog/overview.md +63 -0
  95. package/docs/community/blog/v2-release-note.md +238 -0
  96. package/docs/community/blog/v3-release-note.md +622 -0
  97. package/docs/community/contributing-guide.md +252 -0
  98. package/docs/community/releases.md +23 -0
  99. package/docs/community/showcase.md +24 -0
  100. package/docs/community/team.md +14 -0
  101. package/docs/configure/app/bff/cross-project.md +20 -0
  102. package/docs/configure/app/bff/effect.md +313 -0
  103. package/docs/configure/app/bff/prefix.md +29 -0
  104. package/docs/configure/app/bff/runtime-framework.md +26 -0
  105. package/docs/configure/app/builder-plugins.md +66 -0
  106. package/docs/configure/app/dev/asset-prefix.md +13 -0
  107. package/docs/configure/app/dev/before-start-url.md +17 -0
  108. package/docs/configure/app/dev/client.md +41 -0
  109. package/docs/configure/app/dev/hmr.md +10 -0
  110. package/docs/configure/app/dev/host.md +18 -0
  111. package/docs/configure/app/dev/https.md +77 -0
  112. package/docs/configure/app/dev/lazy-compilation.md +39 -0
  113. package/docs/configure/app/dev/live-reload.md +10 -0
  114. package/docs/configure/app/dev/mock-dir.md +31 -0
  115. package/docs/configure/app/dev/progress-bar.md +19 -0
  116. package/docs/configure/app/dev/server.md +124 -0
  117. package/docs/configure/app/dev/setup-middlewares.md +32 -0
  118. package/docs/configure/app/dev/start-url.md +48 -0
  119. package/docs/configure/app/dev/watch-files.md +27 -0
  120. package/docs/configure/app/dev/write-to-disk.md +10 -0
  121. package/docs/configure/app/experiments/source-build.md +31 -0
  122. package/docs/configure/app/html/app-icon.md +28 -0
  123. package/docs/configure/app/html/crossorigin.md +10 -0
  124. package/docs/configure/app/html/favicon.md +16 -0
  125. package/docs/configure/app/html/inject.md +10 -0
  126. package/docs/configure/app/html/meta.md +24 -0
  127. package/docs/configure/app/html/mount-id.md +10 -0
  128. package/docs/configure/app/html/output-structure.md +10 -0
  129. package/docs/configure/app/html/script-loading.md +10 -0
  130. package/docs/configure/app/html/tags.md +15 -0
  131. package/docs/configure/app/html/template-parameters.md +33 -0
  132. package/docs/configure/app/html/template.md +10 -0
  133. package/docs/configure/app/html/title.md +18 -0
  134. package/docs/configure/app/output/asset-prefix.md +11 -0
  135. package/docs/configure/app/output/assets-retry.md +77 -0
  136. package/docs/configure/app/output/charset.md +10 -0
  137. package/docs/configure/app/output/clean-dist-path.md +16 -0
  138. package/docs/configure/app/output/convert-to-rem.md +79 -0
  139. package/docs/configure/app/output/copy.md +10 -0
  140. package/docs/configure/app/output/css-modules.md +48 -0
  141. package/docs/configure/app/output/data-uri-limit.md +26 -0
  142. package/docs/configure/app/output/disable-css-module-extension.md +55 -0
  143. package/docs/configure/app/output/disable-inline-runtime-chunk.md +41 -0
  144. package/docs/configure/app/output/disable-svgr.md +18 -0
  145. package/docs/configure/app/output/disable-ts-checker.md +49 -0
  146. package/docs/configure/app/output/dist-path.md +43 -0
  147. package/docs/configure/app/output/enable-asset-manifest.md +36 -0
  148. package/docs/configure/app/output/enable-css-module-tsdeclaration.md +28 -0
  149. package/docs/configure/app/output/enable-inline-route-manifests.md +16 -0
  150. package/docs/configure/app/output/externals.md +20 -0
  151. package/docs/configure/app/output/filename-hash.md +10 -0
  152. package/docs/configure/app/output/filename.md +55 -0
  153. package/docs/configure/app/output/inject-styles.md +10 -0
  154. package/docs/configure/app/output/inline-scripts.md +29 -0
  155. package/docs/configure/app/output/inline-styles.md +29 -0
  156. package/docs/configure/app/output/legal-comments.md +18 -0
  157. package/docs/configure/app/output/minify.md +22 -0
  158. package/docs/configure/app/output/override-browserslist.md +22 -0
  159. package/docs/configure/app/output/polyfill.md +12 -0
  160. package/docs/configure/app/output/source-map.md +30 -0
  161. package/docs/configure/app/output/split-route-chunks.md +16 -0
  162. package/docs/configure/app/output/ssg.md +81 -0
  163. package/docs/configure/app/output/ssgByEntries.md +90 -0
  164. package/docs/configure/app/output/svg-default-export.md +30 -0
  165. package/docs/configure/app/output/temp-dir.md +20 -0
  166. package/docs/configure/app/performance/build-cache.md +44 -0
  167. package/docs/configure/app/performance/chunk-split.md +40 -0
  168. package/docs/configure/app/performance/dns-prefetch.md +15 -0
  169. package/docs/configure/app/performance/preconnect.md +16 -0
  170. package/docs/configure/app/performance/prefetch.md +21 -0
  171. package/docs/configure/app/performance/preload.md +23 -0
  172. package/docs/configure/app/performance/print-file-size.md +40 -0
  173. package/docs/configure/app/performance/profile.md +10 -0
  174. package/docs/configure/app/performance/remove-console.md +10 -0
  175. package/docs/configure/app/performance/remove-moment-locale.md +10 -0
  176. package/docs/configure/app/performance/rsdoctor.md +38 -0
  177. package/docs/configure/app/plugins.md +59 -0
  178. package/docs/configure/app/resolve/alias-strategy.md +10 -0
  179. package/docs/configure/app/resolve/alias.md +9 -0
  180. package/docs/configure/app/resolve/condition-names.md +13 -0
  181. package/docs/configure/app/resolve/dedupe.md +9 -0
  182. package/docs/configure/app/resolve/extensions.md +13 -0
  183. package/docs/configure/app/runtime/0-intro.md +58 -0
  184. package/docs/configure/app/runtime/plugins.md +58 -0
  185. package/docs/configure/app/runtime/router.md +35 -0
  186. package/docs/configure/app/security/check-syntax.md +69 -0
  187. package/docs/configure/app/security/nonce.md +15 -0
  188. package/docs/configure/app/security/sri.md +20 -0
  189. package/docs/configure/app/server/base-url.md +26 -0
  190. package/docs/configure/app/server/port.md +18 -0
  191. package/docs/configure/app/server/public-routes.md +22 -0
  192. package/docs/configure/app/server/routes.md +86 -0
  193. package/docs/configure/app/server/rsc.md +22 -0
  194. package/docs/configure/app/server/ssr-by-entries.md +25 -0
  195. package/docs/configure/app/server/ssr.md +80 -0
  196. package/docs/configure/app/server/tsconfig-path.md +59 -0
  197. package/docs/configure/app/source/alias-strategy.md +14 -0
  198. package/docs/configure/app/source/alias.md +23 -0
  199. package/docs/configure/app/source/config-dir.md +20 -0
  200. package/docs/configure/app/source/decorators.md +25 -0
  201. package/docs/configure/app/source/define.md +16 -0
  202. package/docs/configure/app/source/disable-default-entries.md +28 -0
  203. package/docs/configure/app/source/enable-async-entry.md +54 -0
  204. package/docs/configure/app/source/enable-async-pre-entry.md +26 -0
  205. package/docs/configure/app/source/entries-dir.md +35 -0
  206. package/docs/configure/app/source/entries.md +179 -0
  207. package/docs/configure/app/source/exclude.md +10 -0
  208. package/docs/configure/app/source/global-vars.md +106 -0
  209. package/docs/configure/app/source/include.md +36 -0
  210. package/docs/configure/app/source/main-entry-name.md +24 -0
  211. package/docs/configure/app/source/pre-entry.md +10 -0
  212. package/docs/configure/app/source/react-compiler.md +68 -0
  213. package/docs/configure/app/source/transform-import.md +27 -0
  214. package/docs/configure/app/split-chunks.md +17 -0
  215. package/docs/configure/app/tools/autoprefixer.md +44 -0
  216. package/docs/configure/app/tools/bundler-chain.md +26 -0
  217. package/docs/configure/app/tools/css-extract.md +33 -0
  218. package/docs/configure/app/tools/css-loader.md +17 -0
  219. package/docs/configure/app/tools/dev-server.md +113 -0
  220. package/docs/configure/app/tools/html-plugin.md +41 -0
  221. package/docs/configure/app/tools/less.md +81 -0
  222. package/docs/configure/app/tools/lightningcss-loader.md +35 -0
  223. package/docs/configure/app/tools/minify-css.md +53 -0
  224. package/docs/configure/app/tools/postcss.md +34 -0
  225. package/docs/configure/app/tools/rspack.md +10 -0
  226. package/docs/configure/app/tools/sass.md +78 -0
  227. package/docs/configure/app/tools/style-loader.md +10 -0
  228. package/docs/configure/app/tools/swc.md +65 -0
  229. package/docs/configure/app/tools/ts-checker.md +116 -0
  230. package/docs/configure/app/usage.md +276 -0
  231. package/docs/guides/advanced-features/bff/cross-project.md +109 -0
  232. package/docs/guides/advanced-features/bff/data-platform.md +116 -0
  233. package/docs/guides/advanced-features/bff/extend-server.md +120 -0
  234. package/docs/guides/advanced-features/bff/frameworks.md +243 -0
  235. package/docs/guides/advanced-features/bff/function.md +318 -0
  236. package/docs/guides/advanced-features/bff/operators.md +554 -0
  237. package/docs/guides/advanced-features/bff/sdk.md +116 -0
  238. package/docs/guides/advanced-features/bff/upload.md +101 -0
  239. package/docs/guides/advanced-features/bff.md +18 -0
  240. package/docs/guides/advanced-features/build-performance.md +130 -0
  241. package/docs/guides/advanced-features/compatibility.md +120 -0
  242. package/docs/guides/advanced-features/international/advanced.md +128 -0
  243. package/docs/guides/advanced-features/international/api.md +267 -0
  244. package/docs/guides/advanced-features/international/best-practices.md +286 -0
  245. package/docs/guides/advanced-features/international/configuration.md +228 -0
  246. package/docs/guides/advanced-features/international/locale-detection.md +126 -0
  247. package/docs/guides/advanced-features/international/quick-start.md +128 -0
  248. package/docs/guides/advanced-features/international/resource-loading.md +154 -0
  249. package/docs/guides/advanced-features/international/routing.md +173 -0
  250. package/docs/guides/advanced-features/international.md +27 -0
  251. package/docs/guides/advanced-features/low-level.md +46 -0
  252. package/docs/guides/advanced-features/page-performance/code-split.md +77 -0
  253. package/docs/guides/advanced-features/page-performance/inline-assets.md +159 -0
  254. package/docs/guides/advanced-features/page-performance/optimize-bundle.md +97 -0
  255. package/docs/guides/advanced-features/page-performance/react-compiler.md +51 -0
  256. package/docs/guides/advanced-features/server-monitor/logger.md +41 -0
  257. package/docs/guides/advanced-features/server-monitor/metrics.md +58 -0
  258. package/docs/guides/advanced-features/server-monitor/monitors.md +242 -0
  259. package/docs/guides/advanced-features/source-build.md +164 -0
  260. package/docs/guides/advanced-features/web-server.md +288 -0
  261. package/docs/guides/basic-features/alias.md +102 -0
  262. package/docs/guides/basic-features/css/css-in-js.md +72 -0
  263. package/docs/guides/basic-features/css/css-modules.md +212 -0
  264. package/docs/guides/basic-features/css/css.md +27 -0
  265. package/docs/guides/basic-features/css/tailwindcss.md +27 -0
  266. package/docs/guides/basic-features/data/data-cache.md +510 -0
  267. package/docs/guides/basic-features/data/data-fetch.md +415 -0
  268. package/docs/guides/basic-features/data/data-write.md +227 -0
  269. package/docs/guides/basic-features/debug/mock.md +109 -0
  270. package/docs/guides/basic-features/debug/proxy.md +21 -0
  271. package/docs/guides/basic-features/debug/rsdoctor.md +47 -0
  272. package/docs/guides/basic-features/debug/using-storybook.md +112 -0
  273. package/docs/guides/basic-features/deploy.md +458 -0
  274. package/docs/guides/basic-features/env-vars.md +177 -0
  275. package/docs/guides/basic-features/html.md +255 -0
  276. package/docs/guides/basic-features/output-files.md +141 -0
  277. package/docs/guides/basic-features/render/before-render.md +108 -0
  278. package/docs/guides/basic-features/render/overview.md +47 -0
  279. package/docs/guides/basic-features/render/rsc.md +516 -0
  280. package/docs/guides/basic-features/render/ssg.md +228 -0
  281. package/docs/guides/basic-features/render/ssr-cache.md +201 -0
  282. package/docs/guides/basic-features/render/ssr.md +321 -0
  283. package/docs/guides/basic-features/render/streaming-ssr.md +264 -0
  284. package/docs/guides/basic-features/routes/config-routes.md +426 -0
  285. package/docs/guides/basic-features/routes/routes.md +524 -0
  286. package/docs/guides/basic-features/static-assets/json-files.md +120 -0
  287. package/docs/guides/basic-features/static-assets/svg-assets.md +168 -0
  288. package/docs/guides/basic-features/static-assets/wasm-assets.md +62 -0
  289. package/docs/guides/basic-features/static-assets.md +160 -0
  290. package/docs/guides/basic-features/testing/playwright.md +120 -0
  291. package/docs/guides/basic-features/testing/rstest.md +251 -0
  292. package/docs/guides/concept/builder.md +37 -0
  293. package/docs/guides/concept/entries.md +319 -0
  294. package/docs/guides/concept/server.md +35 -0
  295. package/docs/guides/get-started/ai-coding-agents.md +58 -0
  296. package/docs/guides/get-started/glossary.md +63 -0
  297. package/docs/guides/get-started/introduction.md +40 -0
  298. package/docs/guides/get-started/quick-start.md +269 -0
  299. package/docs/guides/get-started/tech-stack.md +91 -0
  300. package/docs/guides/get-started/ultramodern.md +440 -0
  301. package/docs/guides/get-started/upgrade.md +118 -0
  302. package/docs/guides/topic-detail/module-federation/application.md +116 -0
  303. package/docs/guides/topic-detail/module-federation/deploy.md +104 -0
  304. package/docs/guides/topic-detail/module-federation/i18n.md +670 -0
  305. package/docs/guides/topic-detail/module-federation/introduce.md +35 -0
  306. package/docs/guides/topic-detail/module-federation/ssr.md +182 -0
  307. package/docs/guides/topic-detail/module-federation/usage.md +219 -0
  308. package/docs/guides/troubleshooting/builder.md +110 -0
  309. package/docs/guides/troubleshooting/cli.md +35 -0
  310. package/docs/guides/troubleshooting/dependencies.md +119 -0
  311. package/docs/guides/troubleshooting/hmr.md +144 -0
  312. package/docs/guides/upgrade/config.md +954 -0
  313. package/docs/guides/upgrade/entry.md +463 -0
  314. package/docs/guides/upgrade/other.md +183 -0
  315. package/docs/guides/upgrade/overview.md +33 -0
  316. package/docs/guides/upgrade/tailwindcss.md +91 -0
  317. package/docs/guides/upgrade/web-server.md +109 -0
  318. package/docs/index.md +33 -0
  319. package/docs/llms.txt +290 -0
  320. package/docs/plugin/cli-plugins/api.md +573 -0
  321. package/docs/plugin/cli-plugins/life-cycle.md +2 -0
  322. package/docs/plugin/introduction.md +152 -0
  323. package/docs/plugin/official/cli-plugins/plugin-bff.md +5 -0
  324. package/docs/plugin/official/cli-plugins/plugin-ssg.md +5 -0
  325. package/docs/plugin/official/cli-plugins/plugin-styled-components.md +5 -0
  326. package/docs/plugin/official/cli-plugins.md +4 -0
  327. package/docs/plugin/plugin-system.md +238 -0
  328. package/docs/plugin/runtime-plugins/api.md +194 -0
  329. package/docs/plugin/runtime-plugins/life-cycle.md +2 -0
  330. package/docs/plugin/server-plugins/api.md +209 -0
  331. package/docs/plugin/server-plugins/life-cycle.md +13 -0
  332. package/docs/tutorials/examples/csr-auth.md +9 -0
  333. package/docs/tutorials/foundations/introduction.md +16 -0
  334. package/package.json +63 -22
@@ -0,0 +1,524 @@
1
+ # Routing
2
+
3
+ Modern.js supports conventional routing on top of both [React Router](https://reactrouter.com/en/main) and [TanStack Router](https://tanstack.com/router), offering file convention-based routing capabilities and supporting the industry-popular **nested routing** pattern. When an entry is recognized as [conventional routing](/guides/concept/entries.md#conventional-routing), Modern.js automatically generates the corresponding routing structure based on the file system.
4
+
5
+ :::note
6
+
7
+ The routing mentioned in this section all refers to conventional routing.
8
+
9
+ :::
10
+
11
+ :::tip
12
+ This page uses React Router import paths in examples (`@modern-js/runtime/router`).\
13
+ If your project is created with `--router tanstack`, use `@modern-js/plugin-tanstack/runtime` instead.
14
+ :::
15
+
16
+ ## What is Nested Routing
17
+
18
+ Nested routing is a pattern that couples URL segments with the component hierarchy and data. Typically, URL segments determine:
19
+
20
+ - The layouts to render on the page
21
+ - The data dependencies of those layouts
22
+
23
+ Therefore, when using nested routing, the page's routing and UI structure are in correspondence. We will introduce this routing pattern in detail.
24
+
25
+ ```bash
26
+ /user/johnny/profile /user/johnny/posts
27
+ +------------------+ +-----------------+
28
+ | User | | User |
29
+ | +--------------+ | | +-------------+ |
30
+ | | Profile | | +------------> | | Posts | |
31
+ | | | | | | | |
32
+ | +--------------+ | | +-------------+ |
33
+ +------------------+ +-----------------+
34
+ ```
35
+
36
+ ## Routing File Conventions
37
+
38
+ In the `routes/` directory, subdirectory names are mapped to route URLs. Modern.js has two file conventions: `layout.tsx` and `page.tsx`. These files determine the layout hierarchy of the application:
39
+
40
+ - `page.tsx`: This is the content component. When this file exists in a directory, the corresponding route URL is accessible.
41
+ - `layout.tsx`: This is the layout component and controls the layout of all sub-routes in its directory by using `<Outlet>` to represent child components.
42
+
43
+ :::tip
44
+
45
+ `.ts`, `.js`, `.jsx`, or `.tsx` file extensions can be used for the above convention files.
46
+
47
+ :::
48
+
49
+ ### Page
50
+
51
+ The `<Page>` component refers to all `page.tsx` files in the `routes/` directory and is the leaf component for all routes. All routes should end with a `<Page>` component except for wildcard routes.
52
+
53
+ ```tsx title=routes/page.tsx
54
+ export default () => {
55
+ return <div>Hello world</div>;
56
+ };
57
+ ```
58
+
59
+ When the application has the following directory structure:
60
+
61
+ ```bash
62
+ .
63
+ └── routes
64
+ ├── page.tsx
65
+ └── user
66
+ └── page.tsx
67
+ ```
68
+
69
+ The following two routes will be produced:
70
+
71
+ - `/`
72
+ - `/user`
73
+
74
+ ### Layout
75
+
76
+ The `<Layout>` component refers to all `layout.tsx` files in the `routes/` directory. These represent the layout of their respective route segments, using `<Outlet>` for child components.
77
+
78
+ ```tsx title=routes/layout.tsx
79
+ import { Link, Outlet, useLoaderData } from '@modern-js/runtime/router';
80
+
81
+ export default () => {
82
+ return (
83
+ <>
84
+ <Outlet></Outlet>
85
+ </>
86
+ );
87
+ };
88
+ ```
89
+
90
+ :::note
91
+
92
+ `<Outlet>` is an API provided by React Router. For more details, see [Outlet](https://reactrouter.com/en/main/components/outlet#outlet).
93
+
94
+ :::
95
+
96
+ Under different directory structures, the components represented by `<Outlet>` are also different. To illustrate the relationship between `<Layout>` and `<Outlet>`, let's consider the following directory structure:
97
+
98
+ ```bash
99
+ .
100
+ └── routes
101
+ ├── blog
102
+ │ └── page.tsx
103
+ ├── layout.tsx
104
+ ├── page.tsx
105
+ └── user
106
+ ├── layout.tsx
107
+ └── page.tsx
108
+ ```
109
+
110
+ 1. When the route is `/`, the `<Outlet>` in `routes/layout.tsx` represents the component exported from `routes/page.tsx`. The UI structure of the route is:
111
+
112
+ ```tsx
113
+ <Layout>
114
+ <Page />
115
+ </Layout>
116
+ ```
117
+
118
+ 2. When the route is `/blog`, the `<Outlet>` in `routes/layout.tsx` represents the component exported from `routes/blog/page.tsx`. The UI structure of the route is:
119
+
120
+ ```tsx
121
+ <Layout>
122
+ <BlogPage />
123
+ </Layout>
124
+ ```
125
+
126
+ 3. When the route is `/user`, the `<Outlet>` in `routes/layout.tsx` represents the component exported from `routes/user/layout.tsx`. The `<Outlet>` in `routes/user/layout.tsx` represents the component exported from `routes/user/page.tsx`. The UI structure of the route is:
127
+
128
+ ```tsx
129
+ <Layout>
130
+ <UserLayout>
131
+ <UserPage />
132
+ </UserLayout>
133
+ </Layout>
134
+ ```
135
+
136
+ In summary, if there is a `layout.tsx` in the sub-route's directory, the `<Outlet>` in the parent `layout.tsx` corresponds to the `layout.tsx` in the sub-route's directory. Otherwise, it corresponds to the `page.tsx` in the sub-route's directory.
137
+
138
+ ## Dynamic Routes
139
+
140
+ Files and directories named with `[]` are turned into dynamic routes. For instance, consider the following directory structure:
141
+
142
+ ```bash
143
+ .
144
+ └── routes
145
+ ├── [id]
146
+ │ └── page.tsx
147
+ ├── blog
148
+ │ └── page.tsx
149
+ └── page.tsx
150
+ ```
151
+
152
+ The `routes/[id]/page.tsx` file will be converted to the `/:id` route. Apart from the `/blog` route that can be exactly matched, all `/xxx` paths will match this route.
153
+
154
+ In the component, you can use [useParams](/apis/app/runtime/router/router.md#useparams) to get parameters named accordingly.
155
+
156
+ ```tsx
157
+ import { useParams } from '@modern-js/runtime/router';
158
+
159
+ function Blog() {
160
+ const { id } = useParams();
161
+ return <div>current blog ID is: {id}</div>;
162
+ }
163
+ export default Blog;
164
+ ```
165
+
166
+ ## Optional Dynamic Routes
167
+
168
+ Files and directories named with `[$]` are turned into optional dynamic routes. For example, the following directory structure:
169
+
170
+ ```bash
171
+ .
172
+ └── routes
173
+ ├── blog
174
+ │ └── [id$]
175
+ │ └── page.tsx
176
+ └── page.tsx
177
+ ```
178
+
179
+ The `routes/blog/[id$]/page.tsx` file will be converted to the `/blog/:id?` route. All routes under `/blog` will match this route, and the `id` parameter is optional. This route can be used to distinguish between **create** and **edit** actions.
180
+
181
+ ```tsx
182
+ import { useParams } from '@modern-js/runtime/router';
183
+
184
+ function Blog() {
185
+ const { id } = useParams();
186
+ if (id) {
187
+ return <div>current blog ID is: {id}</div>;
188
+ }
189
+
190
+ return <div>create new blog</div>;
191
+ }
192
+ export default Blog;
193
+ ```
194
+
195
+ ## Wildcard Routes
196
+
197
+ If there is a `$.tsx` file in a subdirectory, it acts as a wildcard route component and will be rendered when no other routes match.
198
+
199
+ :::note
200
+ `$.tsx` can be thought of as a special `<Page>` component. If no routes match, `$.tsx` will be rendered as a child component of the `<Layout>`.
201
+ :::
202
+
203
+ :::warning
204
+ If there is no `<Layout>` component in the current directory, `$.tsx` will not have any effect.
205
+ :::
206
+
207
+ For example, consider the following directory structure:
208
+
209
+ ```bash
210
+ .
211
+ └── routes
212
+ ├── blog
213
+ │ ├── $.tsx
214
+ │ └── layout.tsx
215
+ ├── layout.tsx
216
+ └── page.tsx
217
+ ```
218
+
219
+ When you visit `/blog/a` and no routes match, the page will render the `routes/blog/$.tsx` component. The UI structure of the route is:
220
+
221
+ ```tsx
222
+ <RootLayout>
223
+ <BlogLayout>
224
+ <$></$>
225
+ </BlogLayout>
226
+ </RootLayout>
227
+ ```
228
+
229
+ If you want `/blog` to match the `blog/$.tsx` file as well, you need to remove the `blog/layout.tsx` file from the same directory and ensure there are no other sub-routes under `blog`.
230
+
231
+ Similarly, you can use [useParams](/apis/app/runtime/router/router.md#useparams) to capture the remaining part of the URL in the `$.tsx` component.
232
+
233
+ ```ts title="$.tsx"
234
+ import { useParams } from '@modern-js/runtime/router';
235
+
236
+ function Blog() {
237
+ // When the path is `/blog/aaa/bbb`
238
+ const params = useParams();
239
+ console.log(params); // ---> { '*': 'aaa/bbb' }
240
+
241
+ return <div>current blog URL is {params['*']}</div>;
242
+ }
243
+ export default Blog;
244
+ ```
245
+
246
+ ### Custom 404 Page
247
+
248
+ Wildcard routes can be added to any subdirectory in the `routes/` directory. A common use case is to customize a 404 page at any level using a `$.tsx` file.
249
+
250
+ For instance, if you want to show a 404 page for all unmatched routes, you can add a `routes/$.tsx` file:
251
+
252
+ ```bash
253
+ .
254
+ └── routes
255
+ ├── $.tsx
256
+ ├── blog
257
+ │ └── [id$]
258
+ │ └── page.tsx
259
+ ├── layout.tsx
260
+ └── page.tsx
261
+ ```
262
+
263
+ ```tsx
264
+ function Page404() {
265
+ return <div>404 Not Found</div>;
266
+ }
267
+ export default Page404;
268
+ ```
269
+
270
+ At this point, when accessing routes other than `/` or `/blog/*`, they will match the `routes/$.tsx` component and display a 404 page.
271
+
272
+ ## Route Handle Configuration
273
+
274
+ In some scenarios, each route might have its own data which the application needs to access in other components. A common example is retrieving breadcrumb information for the matched route.
275
+
276
+ Modern.js provides a convention where each `Layout`, `$`, or `Page` file can define its own `config` file such as `page.config.ts`. In this file, we conventionally export a named export `handle`, in which you can define any properties:
277
+
278
+ ```ts title="routes/page.config.ts"
279
+ export const handle = {
280
+ breadcrumbName: 'profile',
281
+ };
282
+ ```
283
+
284
+ These defined properties can be accessed using the [`useMatches`](https://reactrouter.com/en/main/hooks/use-matches) hook.
285
+
286
+ ```ts title="routes/layout.ts"
287
+ export default () => {
288
+ const matches = useMatches();
289
+ const breadcrumbs = matches.map(
290
+ matchedRoute => matchedRoute?.handle?.breadcrumbName,
291
+ );
292
+ return <Breadcrumb names={breadcrumbs}></Breadcrumb>;
293
+ };
294
+ ```
295
+
296
+ ## Pathless Layouts
297
+
298
+ When a directory name starts with `__`, the corresponding directory name will not be converted into an actual route path, for example:
299
+
300
+ ```bash
301
+ .
302
+ └── routes
303
+ ├── __auth
304
+ │ ├── layout.tsx
305
+ │ ├── login
306
+ │ │ └── page.tsx
307
+ │ └── sign
308
+ │ └── page.tsx
309
+ ├── layout.tsx
310
+ └── page.tsx
311
+ ```
312
+
313
+ Modern.js will generate `/login` and `/sign` routes, and the `__auth/layout.tsx` component will serve as the layout for `login/page.tsx` and `sign/page.tsx`, but `__auth` will not appear as a path segment in the URL.
314
+
315
+ This feature is useful when you need to create independent layouts or categorize routes without adding additional path segments.
316
+
317
+ ## Pathless File Segments
318
+
319
+ In some cases, a project may need complex routes that do not have independent UI layouts. Creating these routes as regular directories can lead to deeply nested directories.
320
+
321
+ Modern.js supports replacing directory names with `.` to divide route segments. For example, to create a route like `/user/profile/2022/edit`, you can create the following file:
322
+
323
+ ```bash
324
+ └── routes
325
+ ├── user.profile.[id].edit
326
+ │ └── page.tsx
327
+ ├── layout.tsx
328
+ └── page.tsx
329
+ ```
330
+
331
+ When accessed, the resulting route will have the following UI structure:
332
+
333
+ ```tsx
334
+ <RootLayout>
335
+ {/* routes/user.profile.[id].edit/page.tsx */}
336
+ <UserProfileEdit />
337
+ </RootLayout>
338
+ ```
339
+
340
+ ## Route Redirections
341
+
342
+ In some applications, you may need to redirect to another route based on user identity or other data conditions. In Modern.js, you can use a [`Data Loader`](/guides/basic-features/data/data-fetch.md) file to fetch data or use traditional React components with `useEffect`.
343
+
344
+ ### Redirecting in Data Loader
345
+
346
+ Create a `page.data.ts` file in the same directory as `page.tsx`. This file is the Data Loader for that route. In the Data Loader, you can call the `redirect` API to perform route redirections.
347
+
348
+ ```ts title="routes/user/page.data.ts"
349
+ import { redirect } from '@modern-js/runtime/router';
350
+
351
+ export const loader = async () => {
352
+ const user = await getUser();
353
+ if (!user) {
354
+ return redirect('/login');
355
+ }
356
+ return null;
357
+ };
358
+ ```
359
+
360
+ ### Redirecting in a Component
361
+
362
+ To perform a redirection within a component, use the `useNavigate` hook as shown below:
363
+
364
+ ```ts title="routes/user/page.ts"
365
+ import { useNavigate } from '@modern-js/runtime/router';
366
+ import { useEffect } from 'react';
367
+
368
+ export default () => {
369
+ const navigate = useNavigate();
370
+ useEffect(() => {
371
+ getUser().then(user => {
372
+ if (!user) {
373
+ navigate('/login');
374
+ }
375
+ });
376
+ });
377
+
378
+ return <div>Hello World</div>;
379
+ };
380
+ ```
381
+
382
+ ## Error Handling
383
+
384
+ In each directory under `routes/`, developers can define an `error.tsx` file that exports an `<ErrorBoundary>` component. When this component is present, rendering errors in the route directory will be caught by the `ErrorBoundary` component.
385
+
386
+ `<ErrorBoundary>` can return the UI view when an error occurs. If the current level does not declare an `<ErrorBoundary>` component, errors will bubble up to higher-level components until they are caught or thrown. Additionally, when an error occurs within a component, it only affects the route component and its children, leaving the state and view of other components unaffected and interactive.
387
+
388
+
389
+ In the `<ErrorBoundary>` component, you can use [useRouteError](/apis/app/runtime/router/router.md#userouteerror) to obtain specific error information:
390
+
391
+ ```tsx
392
+ import { useRouteError } from '@modern-js/runtime/router';
393
+
394
+ const ErrorBoundary = () => {
395
+ const error = useRouteError();
396
+ return (
397
+ <div>
398
+ <h1>{error.status}</h1>
399
+ <h2>{error.message}</h2>
400
+ </div>
401
+ );
402
+ };
403
+ export default ErrorBoundary;
404
+ ```
405
+
406
+ ## Loading (Experimental)
407
+
408
+ :::info Experimental
409
+ This feature is currently experimental, and its API may change in the future.
410
+ :::
411
+
412
+ In conventional routing, Modern.js automatically splits routes into chunks (each route loads as a separate JS chunk). When users visit a specific route, the corresponding chunk is automatically loaded, effectively reducing the first-screen load time. However, this can lead to a white screen if the route's chunk is not yet loaded.
413
+
414
+ Modern.js supports solving this issue with a `loading.tsx` file. Each directory under `routes/` can create a `loading.tsx` file that exports a `<Loading>` component.
415
+
416
+ :::warning
417
+ If there is no `<Layout>` component in the current directory, `loading.tsx` will not have any effect. To ensure a good user experience, Modern.js recommends adding a root Loading component to each application.
418
+ :::
419
+
420
+ When both this component and a `layout` component exist in the route directory, all child routes under this level will first display the UI from the exported `<Loading>` component until the corresponding JS chunk is fully loaded. For example, with the following file structure:
421
+
422
+ ```bash
423
+ .
424
+ └── routes
425
+ ├── blog
426
+ │ ├── [id]
427
+ │ │ └── page.tsx
428
+ │ └── page.tsx
429
+ ├── layout.tsx
430
+ ├── loading.tsx
431
+ └── page.tsx
432
+ ```
433
+
434
+ When defining a `loading.tsx`, if the route transitions from `/` to `/blog` or from `/blog` to `/blog/123`, and the JS chunk for the route is not yet loaded, the UI from the `<Loading>` component will be displayed first. This results in the following UI structure:
435
+
436
+ ```tsx title=When the route is "/"
437
+ <Layout>
438
+ <Suspense fallback={<Loading />}>
439
+ <Page />
440
+ </Suspense>
441
+ </Layout>
442
+ ```
443
+
444
+ ```tsx title=When the route is "/blog"
445
+ <Layout>
446
+ <Suspense fallback={<Loading />}>
447
+ <BlogPage />
448
+ </Suspense>
449
+ </Layout>
450
+ ```
451
+
452
+ ```tsx title=When the route is "/blog/123"
453
+ <Layout>
454
+ <Suspense fallback={<Loading />}>
455
+ <BlogIdPage />
456
+ </Suspense>
457
+ </Layout>
458
+ ```
459
+
460
+ ## Prefetching
461
+
462
+ Most white screens during route transitions can be optimized by defining a `<Loading>` component. Modern.js also supports navigation warmup with the `prefetch` and `preload` attributes on `<Link>` components.
463
+
464
+ For applications with higher performance requirements, prefetching can further enhance the user experience by reducing the time spent displaying the `<Loading>` component:
465
+
466
+ ```tsx
467
+ <Link prefetch="intent" to="page">
468
+ ```
469
+
470
+ :::tip
471
+
472
+ In SSR projects, same-origin route data returned by the [Data Loader](/guides/basic-features/data/data-fetch.md) is prefetched for matched routes with callable loaders. Set `handle.navigationWarmup.data` to `false` on a route when its loader data should not be requested before navigation.
473
+
474
+ :::
475
+
476
+ By default, same-origin links prefetch the route module and matching loader data when the `<Link>` renders. Modern.js skips these automatic warmups on Save-Data or slow network connections.
477
+
478
+ The `prefetch` attribute has four optional values:
479
+
480
+ - `render`: The default value. When the `<Link>` component is rendered, it begins warming the corresponding route module.
481
+ - `intent`: When users focus, hover, or touch the link, it starts warming the corresponding route module. If the intent is canceled before warmup starts, the warmup is canceled.
482
+ - `viewport`: When the `<Link>` component enters the viewport, it begins warming the corresponding route module.
483
+ - `none`: Disables automatic prefetching. It also disables implicit preload unless an explicit `preload` value is provided.
484
+
485
+ The `preload` attribute accepts the same timing values and defaults to the `prefetch` timing. Explicit `preload` values always win, and `preload={false}` disables preload behavior.
486
+
487
+ To opt a route out of SSR data warmup:
488
+
489
+ ```ts title="routes/page.config.ts"
490
+ export const handle = {
491
+ navigationWarmup: {
492
+ data: false,
493
+ },
494
+ };
495
+ ```
496
+
497
+ :::details Difference Between "render" and Not Using Route Splitting
498
+
499
+ - `render` allows you to control route-module warmup with the position of the `<Link>` component in the tree.
500
+ - `viewport` lets you defer module warmup until the link is close to becoming actionable.
501
+ - SSR data prefetching is enabled by default; use `handle.navigationWarmup.data = false` for routes whose loader data is not safe or useful to fetch before navigation.
502
+
503
+ :::
504
+
505
+
506
+ ## FAQ
507
+
508
+ 1. Why should I import from `@modern-js/runtime/router` or `@modern-js/plugin-tanstack/runtime`?
509
+
510
+ Modern.js provides framework-specific runtime exports:
511
+
512
+ - `@modern-js/runtime/router` for React Router mode.
513
+ - `@modern-js/plugin-tanstack/runtime` for TanStack Router mode.
514
+
515
+ Use the Modern.js runtime export that matches your selected router framework, instead of importing directly from the upstream router package. This avoids dependency duplication and ensures compatibility with Modern.js route generation/runtime behavior.
516
+
517
+ If you encounter API usage issues, check the corresponding upstream docs:
518
+
519
+ - React Router docs for `@modern-js/runtime/router`.
520
+ - TanStack Router docs for `@modern-js/plugin-tanstack/runtime`.
521
+
522
+ :::note
523
+ If you must directly use the React Router package's API (e.g., route behavior wrapped in a unified npm package), you can set [`source.alias`](/configure/app/source/alias.md) to point `react-router` to the project's dependency, avoiding the issue of two React Router versions.
524
+ :::
@@ -0,0 +1,120 @@
1
+ # Import JSON Files
2
+
3
+ Modern.js supports import JSON files in code by default. You can use Rsbuild plugins to support importing [YAML](https://yaml.org/) and [Toml](https://toml.io/en/) files and converting them to JSON format.
4
+
5
+ ## JSON file
6
+
7
+ You can import JSON files directly in JavaScript files.
8
+
9
+ ### Example
10
+
11
+ ```json title="example.json"
12
+ {
13
+ "name": "foo",
14
+ "items": [1, 2]
15
+ }
16
+ ```
17
+
18
+ ```js title="index.js"
19
+ import example from './example.json';
20
+
21
+ console.log(example.name); // 'foo';
22
+ console.log(example.items); // [1, 2];
23
+ ```
24
+
25
+ ### Named Import
26
+
27
+ Modern.js does not support importing JSON files via named import yet:
28
+
29
+ ```js
30
+ import { name } from './example.json';
31
+ ```
32
+
33
+ ## YAML file
34
+
35
+ YAML is a data serialization language commonly used for writing configuration files.
36
+
37
+ You can configure the [YAML plugin](https://github.com/rstackjs/rsbuild-plugin-yaml) in `modern.config.ts` to support importing `.yaml` or `.yml` files, they will be automatically converted to JSON format.
38
+
39
+ ```ts
40
+ import { defineConfig } from '@modern-js/app-tools';
41
+ import { pluginYaml } from '@rsbuild/plugin-yaml';
42
+
43
+ export default defineConfig({
44
+ plugins: [pluginYaml()],
45
+ });
46
+ ```
47
+
48
+ ### Example
49
+
50
+ ```yaml title="example.yaml"
51
+ ---
52
+ hello: world
53
+ foo:
54
+ bar: baz
55
+ ```
56
+
57
+ ```js
58
+ import example from './example.yaml';
59
+
60
+ console.log(example.hello); // 'world';
61
+ console.log(example.foo); // { bar: 'baz' };
62
+ ```
63
+
64
+ ### Add type declaration
65
+
66
+ When you import a YAML file in your TypeScript code, please create a `src/global.d.ts` file in your project and add the corresponding type declaration:
67
+
68
+ ```ts title="src/global.d.ts"
69
+ declare module '*.yaml' {
70
+ const content: Record<string, any>;
71
+ export default content;
72
+ }
73
+
74
+ declare module '*.yml' {
75
+ const content: Record<string, any>;
76
+ export default content;
77
+ }
78
+ ```
79
+
80
+ ## Toml file
81
+
82
+ Toml is a semantically explicit, easy-to-read configuration file format.
83
+
84
+ You can configure the [TOML plugin](https://github.com/rstackjs/rsbuild-plugin-toml) in `modern.config.ts` to support importing `.toml` files, it will be automatically converted to JSON format.
85
+
86
+ ```ts
87
+ import { defineConfig } from '@modern-js/app-tools';
88
+ import { pluginToml } from '@rsbuild/plugin-toml';
89
+
90
+ export default defineConfig({
91
+ plugins: [pluginToml()],
92
+ });
93
+ ```
94
+
95
+ ### Example
96
+
97
+ ```toml title="example.toml"
98
+ hello = "world"
99
+
100
+ [foo]
101
+ bar = "baz"
102
+ ```
103
+
104
+ ```js
105
+ import example from './example.toml';
106
+
107
+ console.log(example.hello); // 'world';
108
+ console.log(example.foo); // { bar: 'baz' };
109
+ ```
110
+
111
+ ### Add type declaration
112
+
113
+ When you import Toml files in TypeScript code, please create a `src/global.d.ts` file in your project and add the corresponding type declarations:
114
+
115
+ ```ts title="src/global.d.ts"
116
+ declare module '*.toml' {
117
+ const content: Record<string, any>;
118
+ export default content;
119
+ }
120
+ ```