vinext 0.0.30 → 0.0.32

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 (435) hide show
  1. package/README.md +15 -7
  2. package/dist/build/prerender.d.ts +188 -0
  3. package/dist/build/prerender.js +675 -0
  4. package/dist/build/prerender.js.map +1 -0
  5. package/dist/build/report.d.ts +45 -46
  6. package/dist/build/report.js +581 -276
  7. package/dist/build/report.js.map +1 -1
  8. package/dist/build/run-prerender.d.ts +62 -0
  9. package/dist/build/run-prerender.js +183 -0
  10. package/dist/build/run-prerender.js.map +1 -0
  11. package/dist/build/server-manifest.d.ts +19 -0
  12. package/dist/build/server-manifest.js +29 -0
  13. package/dist/build/server-manifest.js.map +1 -0
  14. package/dist/build/static-export.d.ts +51 -66
  15. package/dist/build/static-export.js +51 -545
  16. package/dist/build/static-export.js.map +1 -1
  17. package/dist/check.d.ts +26 -24
  18. package/dist/check.js +681 -571
  19. package/dist/check.js.map +1 -1
  20. package/dist/cli.d.ts +1 -15
  21. package/dist/cli.js +432 -491
  22. package/dist/cli.js.map +1 -1
  23. package/dist/client/entry.d.ts +1 -2
  24. package/dist/client/entry.js +49 -62
  25. package/dist/client/entry.js.map +1 -1
  26. package/dist/client/validate-module-path.d.ts +4 -1
  27. package/dist/client/validate-module-path.js +23 -28
  28. package/dist/client/validate-module-path.js.map +1 -1
  29. package/dist/client/vinext-next-data.d.ts +15 -20
  30. package/dist/client/vinext-next-data.js +0 -1
  31. package/dist/cloudflare/index.d.ts +3 -8
  32. package/dist/cloudflare/index.js +3 -8
  33. package/dist/cloudflare/kv-cache-handler.d.ts +95 -105
  34. package/dist/cloudflare/kv-cache-handler.js +354 -380
  35. package/dist/cloudflare/kv-cache-handler.js.map +1 -1
  36. package/dist/cloudflare/tpr.d.ts +36 -34
  37. package/dist/cloudflare/tpr.js +460 -603
  38. package/dist/cloudflare/tpr.js.map +1 -1
  39. package/dist/config/config-matchers.d.ts +31 -40
  40. package/dist/config/config-matchers.js +727 -936
  41. package/dist/config/config-matchers.js.map +1 -1
  42. package/dist/config/dotenv.d.ts +18 -11
  43. package/dist/config/dotenv.js +79 -84
  44. package/dist/config/dotenv.js.map +1 -1
  45. package/dist/config/next-config.d.ts +156 -146
  46. package/dist/config/next-config.js +376 -464
  47. package/dist/config/next-config.js.map +1 -1
  48. package/dist/deploy.d.ts +87 -96
  49. package/dist/deploy.js +490 -628
  50. package/dist/deploy.js.map +1 -1
  51. package/dist/entries/app-browser-entry.d.ts +4 -1
  52. package/dist/entries/app-browser-entry.js +12 -8
  53. package/dist/entries/app-browser-entry.js.map +1 -1
  54. package/dist/entries/app-rsc-entry.d.ts +33 -20
  55. package/dist/entries/app-rsc-entry.js +444 -212
  56. package/dist/entries/app-rsc-entry.js.map +1 -1
  57. package/dist/entries/app-ssr-entry.d.ts +9 -1
  58. package/dist/entries/app-ssr-entry.js +61 -28
  59. package/dist/entries/app-ssr-entry.js.map +1 -1
  60. package/dist/entries/pages-client-entry.d.ts +6 -2
  61. package/dist/entries/pages-client-entry.js +30 -33
  62. package/dist/entries/pages-client-entry.js.map +1 -1
  63. package/dist/entries/pages-entry-helpers.d.ts +5 -1
  64. package/dist/entries/pages-entry-helpers.js +17 -14
  65. package/dist/entries/pages-entry-helpers.js.map +1 -1
  66. package/dist/entries/pages-server-entry.d.ts +6 -2
  67. package/dist/entries/pages-server-entry.js +86 -114
  68. package/dist/entries/pages-server-entry.js.map +1 -1
  69. package/dist/index.d.ts +92 -60
  70. package/dist/index.js +2151 -3133
  71. package/dist/index.js.map +1 -1
  72. package/dist/init.d.ts +40 -37
  73. package/dist/init.js +201 -258
  74. package/dist/init.js.map +1 -1
  75. package/dist/plugins/async-hooks-stub.d.ts +7 -3
  76. package/dist/plugins/async-hooks-stub.js +39 -42
  77. package/dist/plugins/async-hooks-stub.js.map +1 -1
  78. package/dist/plugins/client-reference-dedup.d.ts +7 -3
  79. package/dist/plugins/client-reference-dedup.js +63 -88
  80. package/dist/plugins/client-reference-dedup.js.map +1 -1
  81. package/dist/routing/app-router.d.ts +100 -96
  82. package/dist/routing/app-router.js +560 -670
  83. package/dist/routing/app-router.js.map +1 -1
  84. package/dist/routing/file-matcher.d.ts +18 -15
  85. package/dist/routing/file-matcher.js +65 -65
  86. package/dist/routing/file-matcher.js.map +1 -1
  87. package/dist/routing/pages-router.d.ts +23 -24
  88. package/dist/routing/pages-router.js +147 -172
  89. package/dist/routing/pages-router.js.map +1 -1
  90. package/dist/routing/route-trie.d.ts +23 -20
  91. package/dist/routing/route-trie.js +131 -151
  92. package/dist/routing/route-trie.js.map +1 -1
  93. package/dist/routing/route-validation.d.ts +5 -2
  94. package/dist/routing/route-validation.js +98 -130
  95. package/dist/routing/route-validation.js.map +1 -1
  96. package/dist/routing/utils.d.ts +10 -7
  97. package/dist/routing/utils.js +75 -111
  98. package/dist/routing/utils.js.map +1 -1
  99. package/dist/server/api-handler.d.ts +8 -13
  100. package/dist/server/api-handler.js +160 -193
  101. package/dist/server/api-handler.js.map +1 -1
  102. package/dist/server/app-router-entry.d.ts +6 -16
  103. package/dist/server/app-router-entry.js +26 -54
  104. package/dist/server/app-router-entry.js.map +1 -1
  105. package/dist/server/dev-module-runner.d.ts +11 -64
  106. package/dist/server/dev-module-runner.js +89 -101
  107. package/dist/server/dev-module-runner.js.map +1 -1
  108. package/dist/server/dev-origin-check.d.ts +12 -10
  109. package/dist/server/dev-origin-check.js +98 -108
  110. package/dist/server/dev-origin-check.js.map +1 -1
  111. package/dist/server/dev-server.d.ts +19 -15
  112. package/dist/server/dev-server.js +543 -871
  113. package/dist/server/dev-server.js.map +1 -1
  114. package/dist/server/html.d.ts +4 -1
  115. package/dist/server/html.js +25 -26
  116. package/dist/server/html.js.map +1 -1
  117. package/dist/server/image-optimization.d.ts +31 -28
  118. package/dist/server/image-optimization.js +181 -210
  119. package/dist/server/image-optimization.js.map +1 -1
  120. package/dist/server/instrumentation.d.ts +34 -59
  121. package/dist/server/instrumentation.js +112 -125
  122. package/dist/server/instrumentation.js.map +1 -1
  123. package/dist/server/isr-cache.d.ts +16 -26
  124. package/dist/server/isr-cache.js +106 -128
  125. package/dist/server/isr-cache.js.map +1 -1
  126. package/dist/server/metadata-routes.d.ts +85 -88
  127. package/dist/server/metadata-routes.js +270 -317
  128. package/dist/server/metadata-routes.js.map +1 -1
  129. package/dist/server/middleware-codegen.d.ts +7 -4
  130. package/dist/server/middleware-codegen.js +61 -61
  131. package/dist/server/middleware-codegen.js.map +1 -1
  132. package/dist/server/middleware-request-headers.d.ts +8 -6
  133. package/dist/server/middleware-request-headers.js +47 -65
  134. package/dist/server/middleware-request-headers.js.map +1 -1
  135. package/dist/server/middleware.d.ts +32 -47
  136. package/dist/server/middleware.js +261 -409
  137. package/dist/server/middleware.js.map +1 -1
  138. package/dist/server/normalize-path.d.ts +4 -1
  139. package/dist/server/normalize-path.js +33 -47
  140. package/dist/server/normalize-path.js.map +1 -1
  141. package/dist/server/pages-i18n.d.ts +38 -30
  142. package/dist/server/pages-i18n.js +112 -139
  143. package/dist/server/pages-i18n.js.map +1 -1
  144. package/dist/server/prod-server.d.ts +19 -31
  145. package/dist/server/prod-server.js +715 -945
  146. package/dist/server/prod-server.js.map +1 -1
  147. package/dist/server/request-log.d.ts +18 -12
  148. package/dist/server/request-log.js +45 -52
  149. package/dist/server/request-log.js.map +1 -1
  150. package/dist/server/request-pipeline.d.ts +9 -17
  151. package/dist/server/request-pipeline.js +133 -184
  152. package/dist/server/request-pipeline.js.map +1 -1
  153. package/dist/server/worker-utils.d.ts +4 -1
  154. package/dist/server/worker-utils.js +31 -37
  155. package/dist/server/worker-utils.js.map +1 -1
  156. package/dist/shims/amp.d.ts +5 -2
  157. package/dist/shims/amp.js +19 -15
  158. package/dist/shims/amp.js.map +1 -1
  159. package/dist/shims/app.d.ts +8 -10
  160. package/dist/shims/app.js +0 -1
  161. package/dist/shims/cache-runtime.d.ts +20 -45
  162. package/dist/shims/cache-runtime.js +271 -422
  163. package/dist/shims/cache-runtime.js.map +1 -1
  164. package/dist/shims/cache.d.ts +130 -121
  165. package/dist/shims/cache.js +339 -427
  166. package/dist/shims/cache.js.map +1 -1
  167. package/dist/shims/client-only.d.ts +1 -18
  168. package/dist/shims/client-only.js +0 -17
  169. package/dist/shims/compat-router.d.ts +6 -1
  170. package/dist/shims/compat-router.js +23 -19
  171. package/dist/shims/compat-router.js.map +1 -1
  172. package/dist/shims/config.d.ts +7 -5
  173. package/dist/shims/config.js +16 -23
  174. package/dist/shims/config.js.map +1 -1
  175. package/dist/shims/constants.d.ts +119 -118
  176. package/dist/shims/constants.js +159 -164
  177. package/dist/shims/constants.js.map +1 -1
  178. package/dist/shims/document.d.ts +20 -16
  179. package/dist/shims/document.js +41 -22
  180. package/dist/shims/document.js.map +1 -1
  181. package/dist/shims/dynamic.d.ts +13 -22
  182. package/dist/shims/dynamic.js +122 -136
  183. package/dist/shims/dynamic.js.map +1 -1
  184. package/dist/shims/error-boundary.d.ts +22 -15
  185. package/dist/shims/error-boundary.js +81 -79
  186. package/dist/shims/error-boundary.js.map +1 -1
  187. package/dist/shims/error.d.ts +11 -12
  188. package/dist/shims/error.js +35 -39
  189. package/dist/shims/error.js.map +1 -1
  190. package/dist/shims/fetch-cache.d.ts +16 -14
  191. package/dist/shims/fetch-cache.js +439 -645
  192. package/dist/shims/fetch-cache.js.map +1 -1
  193. package/dist/shims/font-google-base.d.ts +28 -26
  194. package/dist/shims/font-google-base.js +238 -325
  195. package/dist/shims/font-google-base.js.map +1 -1
  196. package/dist/shims/font-google.d.ts +3 -3
  197. package/dist/shims/font-google.generated.d.ts +1928 -1924
  198. package/dist/shims/font-google.generated.js +1928 -2133
  199. package/dist/shims/font-google.generated.js.map +1 -1
  200. package/dist/shims/font-google.js +3 -3
  201. package/dist/shims/font-local.d.ts +28 -26
  202. package/dist/shims/font-local.js +204 -260
  203. package/dist/shims/font-local.js.map +1 -1
  204. package/dist/shims/form.d.ts +13 -27
  205. package/dist/shims/form.js +128 -180
  206. package/dist/shims/form.js.map +1 -1
  207. package/dist/shims/head-state.d.ts +8 -13
  208. package/dist/shims/head-state.js +25 -42
  209. package/dist/shims/head-state.js.map +1 -1
  210. package/dist/shims/head.d.ts +17 -20
  211. package/dist/shims/head.js +194 -250
  212. package/dist/shims/head.js.map +1 -1
  213. package/dist/shims/headers.d.ts +84 -78
  214. package/dist/shims/headers.js +447 -575
  215. package/dist/shims/headers.js.map +1 -1
  216. package/dist/shims/i18n-context.d.ts +16 -20
  217. package/dist/shims/i18n-context.js +35 -48
  218. package/dist/shims/i18n-context.js.map +1 -1
  219. package/dist/shims/i18n-state.d.ts +8 -14
  220. package/dist/shims/i18n-state.js +34 -42
  221. package/dist/shims/i18n-state.js.map +1 -1
  222. package/dist/shims/image-config.d.ts +11 -8
  223. package/dist/shims/image-config.js +50 -83
  224. package/dist/shims/image-config.js.map +1 -1
  225. package/dist/shims/image.d.ts +37 -46
  226. package/dist/shims/image.js +283 -308
  227. package/dist/shims/image.js.map +1 -1
  228. package/dist/shims/internal/api-utils.d.ts +7 -4
  229. package/dist/shims/internal/api-utils.js +0 -6
  230. package/dist/shims/internal/app-router-context.d.ts +22 -17
  231. package/dist/shims/internal/app-router-context.js +17 -13
  232. package/dist/shims/internal/app-router-context.js.map +1 -1
  233. package/dist/shims/internal/cookies.d.ts +2 -9
  234. package/dist/shims/internal/cookies.js +2 -9
  235. package/dist/shims/internal/parse-cookie-header.d.ts +4 -1
  236. package/dist/shims/internal/parse-cookie-header.js +29 -29
  237. package/dist/shims/internal/parse-cookie-header.js.map +1 -1
  238. package/dist/shims/internal/router-context.d.ts +7 -1
  239. package/dist/shims/internal/router-context.js +11 -7
  240. package/dist/shims/internal/router-context.js.map +1 -1
  241. package/dist/shims/internal/utils.d.ts +40 -37
  242. package/dist/shims/internal/utils.js +24 -30
  243. package/dist/shims/internal/utils.js.map +1 -1
  244. package/dist/shims/internal/work-unit-async-storage.d.ts +6 -10
  245. package/dist/shims/internal/work-unit-async-storage.js +14 -11
  246. package/dist/shims/internal/work-unit-async-storage.js.map +1 -1
  247. package/dist/shims/layout-segment-context.d.ts +11 -14
  248. package/dist/shims/layout-segment-context.js +24 -23
  249. package/dist/shims/layout-segment-context.js.map +1 -1
  250. package/dist/shims/legacy-image.d.ts +39 -46
  251. package/dist/shims/legacy-image.js +47 -42
  252. package/dist/shims/legacy-image.js.map +1 -1
  253. package/dist/shims/link.d.ts +32 -36
  254. package/dist/shims/link.js +255 -391
  255. package/dist/shims/link.js.map +1 -1
  256. package/dist/shims/metadata.d.ts +210 -202
  257. package/dist/shims/metadata.js +545 -546
  258. package/dist/shims/metadata.js.map +1 -1
  259. package/dist/shims/navigation-state.d.ts +10 -18
  260. package/dist/shims/navigation-state.js +66 -74
  261. package/dist/shims/navigation-state.js.map +1 -1
  262. package/dist/shims/navigation.d.ts +59 -63
  263. package/dist/shims/navigation.js +505 -704
  264. package/dist/shims/navigation.js.map +1 -1
  265. package/dist/shims/og.d.ts +2 -20
  266. package/dist/shims/og.js +2 -19
  267. package/dist/shims/readonly-url-search-params.d.ts +8 -5
  268. package/dist/shims/readonly-url-search-params.js +26 -22
  269. package/dist/shims/readonly-url-search-params.js.map +1 -1
  270. package/dist/shims/request-context.d.ts +8 -5
  271. package/dist/shims/request-context.js +50 -60
  272. package/dist/shims/request-context.js.map +1 -1
  273. package/dist/shims/request-state-types.d.ts +11 -11
  274. package/dist/shims/request-state-types.js +0 -1
  275. package/dist/shims/router-state.d.ts +13 -10
  276. package/dist/shims/router-state.js +34 -43
  277. package/dist/shims/router-state.js.map +1 -1
  278. package/dist/shims/router.d.ts +81 -85
  279. package/dist/shims/router.js +506 -628
  280. package/dist/shims/router.js.map +1 -1
  281. package/dist/shims/script.d.ts +39 -48
  282. package/dist/shims/script.js +107 -160
  283. package/dist/shims/script.js.map +1 -1
  284. package/dist/shims/server-only.d.ts +1 -19
  285. package/dist/shims/server-only.js +0 -18
  286. package/dist/shims/server.d.ts +213 -164
  287. package/dist/shims/server.js +545 -478
  288. package/dist/shims/server.js.map +1 -1
  289. package/dist/shims/unified-request-context.d.ts +20 -20
  290. package/dist/shims/unified-request-context.js +81 -99
  291. package/dist/shims/unified-request-context.js.map +1 -1
  292. package/dist/shims/url-safety.d.ts +4 -1
  293. package/dist/shims/url-safety.js +15 -11
  294. package/dist/shims/url-safety.js.map +1 -1
  295. package/dist/shims/url-utils.d.ts +8 -5
  296. package/dist/shims/url-utils.js +62 -93
  297. package/dist/shims/url-utils.js.map +1 -1
  298. package/dist/shims/web-vitals.d.ts +10 -8
  299. package/dist/shims/web-vitals.js +9 -15
  300. package/dist/shims/web-vitals.js.map +1 -1
  301. package/dist/utils/base-path.d.ts +5 -2
  302. package/dist/utils/base-path.js +21 -19
  303. package/dist/utils/base-path.js.map +1 -1
  304. package/dist/utils/domain-locale.d.ts +17 -9
  305. package/dist/utils/domain-locale.js +36 -56
  306. package/dist/utils/domain-locale.js.map +1 -1
  307. package/dist/utils/hash.d.ts +4 -1
  308. package/dist/utils/hash.js +19 -17
  309. package/dist/utils/hash.js.map +1 -1
  310. package/dist/utils/manifest-paths.d.ts +6 -3
  311. package/dist/utils/manifest-paths.js +15 -16
  312. package/dist/utils/manifest-paths.js.map +1 -1
  313. package/dist/utils/project.d.ts +13 -11
  314. package/dist/utils/project.js +169 -216
  315. package/dist/utils/project.js.map +1 -1
  316. package/dist/utils/query.d.ts +8 -6
  317. package/dist/utils/query.js +57 -67
  318. package/dist/utils/query.js.map +1 -1
  319. package/package.json +10 -9
  320. package/dist/build/report.d.ts.map +0 -1
  321. package/dist/build/static-export.d.ts.map +0 -1
  322. package/dist/check.d.ts.map +0 -1
  323. package/dist/cli.d.ts.map +0 -1
  324. package/dist/client/entry.d.ts.map +0 -1
  325. package/dist/client/validate-module-path.d.ts.map +0 -1
  326. package/dist/client/vinext-next-data.d.ts.map +0 -1
  327. package/dist/client/vinext-next-data.js.map +0 -1
  328. package/dist/cloudflare/index.d.ts.map +0 -1
  329. package/dist/cloudflare/index.js.map +0 -1
  330. package/dist/cloudflare/kv-cache-handler.d.ts.map +0 -1
  331. package/dist/cloudflare/tpr.d.ts.map +0 -1
  332. package/dist/config/config-matchers.d.ts.map +0 -1
  333. package/dist/config/dotenv.d.ts.map +0 -1
  334. package/dist/config/next-config.d.ts.map +0 -1
  335. package/dist/deploy.d.ts.map +0 -1
  336. package/dist/entries/app-browser-entry.d.ts.map +0 -1
  337. package/dist/entries/app-rsc-entry.d.ts.map +0 -1
  338. package/dist/entries/app-ssr-entry.d.ts.map +0 -1
  339. package/dist/entries/pages-client-entry.d.ts.map +0 -1
  340. package/dist/entries/pages-entry-helpers.d.ts.map +0 -1
  341. package/dist/entries/pages-server-entry.d.ts.map +0 -1
  342. package/dist/index.d.ts.map +0 -1
  343. package/dist/init.d.ts.map +0 -1
  344. package/dist/plugins/async-hooks-stub.d.ts.map +0 -1
  345. package/dist/plugins/client-reference-dedup.d.ts.map +0 -1
  346. package/dist/routing/app-router.d.ts.map +0 -1
  347. package/dist/routing/file-matcher.d.ts.map +0 -1
  348. package/dist/routing/pages-router.d.ts.map +0 -1
  349. package/dist/routing/route-trie.d.ts.map +0 -1
  350. package/dist/routing/route-validation.d.ts.map +0 -1
  351. package/dist/routing/utils.d.ts.map +0 -1
  352. package/dist/server/api-handler.d.ts.map +0 -1
  353. package/dist/server/app-router-entry.d.ts.map +0 -1
  354. package/dist/server/dev-module-runner.d.ts.map +0 -1
  355. package/dist/server/dev-origin-check.d.ts.map +0 -1
  356. package/dist/server/dev-server.d.ts.map +0 -1
  357. package/dist/server/html.d.ts.map +0 -1
  358. package/dist/server/image-optimization.d.ts.map +0 -1
  359. package/dist/server/instrumentation.d.ts.map +0 -1
  360. package/dist/server/isr-cache.d.ts.map +0 -1
  361. package/dist/server/metadata-routes.d.ts.map +0 -1
  362. package/dist/server/middleware-codegen.d.ts.map +0 -1
  363. package/dist/server/middleware-request-headers.d.ts.map +0 -1
  364. package/dist/server/middleware.d.ts.map +0 -1
  365. package/dist/server/normalize-path.d.ts.map +0 -1
  366. package/dist/server/pages-i18n.d.ts.map +0 -1
  367. package/dist/server/prod-server.d.ts.map +0 -1
  368. package/dist/server/request-log.d.ts.map +0 -1
  369. package/dist/server/request-pipeline.d.ts.map +0 -1
  370. package/dist/server/worker-utils.d.ts.map +0 -1
  371. package/dist/shims/amp.d.ts.map +0 -1
  372. package/dist/shims/app.d.ts.map +0 -1
  373. package/dist/shims/app.js.map +0 -1
  374. package/dist/shims/cache-runtime.d.ts.map +0 -1
  375. package/dist/shims/cache.d.ts.map +0 -1
  376. package/dist/shims/client-only.d.ts.map +0 -1
  377. package/dist/shims/client-only.js.map +0 -1
  378. package/dist/shims/compat-router.d.ts.map +0 -1
  379. package/dist/shims/config.d.ts.map +0 -1
  380. package/dist/shims/constants.d.ts.map +0 -1
  381. package/dist/shims/document.d.ts.map +0 -1
  382. package/dist/shims/dynamic.d.ts.map +0 -1
  383. package/dist/shims/error-boundary.d.ts.map +0 -1
  384. package/dist/shims/error.d.ts.map +0 -1
  385. package/dist/shims/fetch-cache.d.ts.map +0 -1
  386. package/dist/shims/font-google-base.d.ts.map +0 -1
  387. package/dist/shims/font-google.d.ts.map +0 -1
  388. package/dist/shims/font-google.generated.d.ts.map +0 -1
  389. package/dist/shims/font-google.js.map +0 -1
  390. package/dist/shims/font-local.d.ts.map +0 -1
  391. package/dist/shims/form.d.ts.map +0 -1
  392. package/dist/shims/head-state.d.ts.map +0 -1
  393. package/dist/shims/head.d.ts.map +0 -1
  394. package/dist/shims/headers.d.ts.map +0 -1
  395. package/dist/shims/i18n-context.d.ts.map +0 -1
  396. package/dist/shims/i18n-state.d.ts.map +0 -1
  397. package/dist/shims/image-config.d.ts.map +0 -1
  398. package/dist/shims/image.d.ts.map +0 -1
  399. package/dist/shims/internal/api-utils.d.ts.map +0 -1
  400. package/dist/shims/internal/api-utils.js.map +0 -1
  401. package/dist/shims/internal/app-router-context.d.ts.map +0 -1
  402. package/dist/shims/internal/cookies.d.ts.map +0 -1
  403. package/dist/shims/internal/cookies.js.map +0 -1
  404. package/dist/shims/internal/parse-cookie-header.d.ts.map +0 -1
  405. package/dist/shims/internal/router-context.d.ts.map +0 -1
  406. package/dist/shims/internal/utils.d.ts.map +0 -1
  407. package/dist/shims/internal/work-unit-async-storage.d.ts.map +0 -1
  408. package/dist/shims/layout-segment-context.d.ts.map +0 -1
  409. package/dist/shims/legacy-image.d.ts.map +0 -1
  410. package/dist/shims/link.d.ts.map +0 -1
  411. package/dist/shims/metadata.d.ts.map +0 -1
  412. package/dist/shims/navigation-state.d.ts.map +0 -1
  413. package/dist/shims/navigation.d.ts.map +0 -1
  414. package/dist/shims/og.d.ts.map +0 -1
  415. package/dist/shims/og.js.map +0 -1
  416. package/dist/shims/readonly-url-search-params.d.ts.map +0 -1
  417. package/dist/shims/request-context.d.ts.map +0 -1
  418. package/dist/shims/request-state-types.d.ts.map +0 -1
  419. package/dist/shims/request-state-types.js.map +0 -1
  420. package/dist/shims/router-state.d.ts.map +0 -1
  421. package/dist/shims/router.d.ts.map +0 -1
  422. package/dist/shims/script.d.ts.map +0 -1
  423. package/dist/shims/server-only.d.ts.map +0 -1
  424. package/dist/shims/server-only.js.map +0 -1
  425. package/dist/shims/server.d.ts.map +0 -1
  426. package/dist/shims/unified-request-context.d.ts.map +0 -1
  427. package/dist/shims/url-safety.d.ts.map +0 -1
  428. package/dist/shims/url-utils.d.ts.map +0 -1
  429. package/dist/shims/web-vitals.d.ts.map +0 -1
  430. package/dist/utils/base-path.d.ts.map +0 -1
  431. package/dist/utils/domain-locale.d.ts.map +0 -1
  432. package/dist/utils/hash.d.ts.map +0 -1
  433. package/dist/utils/manifest-paths.d.ts.map +0 -1
  434. package/dist/utils/project.d.ts.map +0 -1
  435. package/dist/utils/query.d.ts.map +0 -1
@@ -1,694 +1,572 @@
1
- /**
2
- * next/router shim
3
- *
4
- * Provides useRouter() hook and Router singleton for Pages Router.
5
- * Backed by the browser History API. Supports client-side navigation
6
- * by fetching new page data and re-rendering the React root.
7
- */
8
- import { useState, useEffect, useCallback, useMemo, createElement } from "react";
9
1
  import { RouterContext } from "./internal/router-context.js";
10
2
  import { isValidModulePath } from "../client/validate-module-path.js";
11
- import { toBrowserNavigationHref, toSameOriginAppPath } from "./url-utils.js";
12
3
  import { stripBasePath } from "../utils/base-path.js";
4
+ import { toBrowserNavigationHref, toSameOriginAppPath } from "./url-utils.js";
13
5
  import { addLocalePrefix, getDomainLocaleUrl } from "../utils/domain-locale.js";
14
- import { addQueryParam, appendSearchParamsToUrl, urlQueryToSearchParams, } from "../utils/query.js";
6
+ import { addQueryParam, appendSearchParamsToUrl, urlQueryToSearchParams } from "../utils/query.js";
7
+ import { createElement, useCallback, useEffect, useMemo, useState } from "react";
8
+ //#region src/shims/router.ts
9
+ /**
10
+ * next/router shim
11
+ *
12
+ * Provides useRouter() hook and Router singleton for Pages Router.
13
+ * Backed by the browser History API. Supports client-side navigation
14
+ * by fetching new page data and re-rendering the React root.
15
+ */
15
16
  /** basePath from next.config.js, injected by the plugin at build time */
16
17
  const __basePath = process.env.__NEXT_ROUTER_BASEPATH ?? "";
17
18
  function createRouterEvents() {
18
- const listeners = new Map();
19
- return {
20
- on(event, handler) {
21
- if (!listeners.has(event))
22
- listeners.set(event, new Set());
23
- listeners.get(event).add(handler);
24
- },
25
- off(event, handler) {
26
- listeners.get(event)?.delete(handler);
27
- },
28
- emit(event, ...args) {
29
- listeners.get(event)?.forEach((handler) => handler(...args));
30
- },
31
- };
19
+ const listeners = /* @__PURE__ */ new Map();
20
+ return {
21
+ on(event, handler) {
22
+ if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
23
+ listeners.get(event).add(handler);
24
+ },
25
+ off(event, handler) {
26
+ listeners.get(event)?.delete(handler);
27
+ },
28
+ emit(event, ...args) {
29
+ listeners.get(event)?.forEach((handler) => handler(...args));
30
+ }
31
+ };
32
32
  }
33
- // Singleton events instance
34
33
  const routerEvents = createRouterEvents();
35
34
  function resolveUrl(url) {
36
- if (typeof url === "string")
37
- return url;
38
- let result = url.pathname ?? "/";
39
- if (url.query) {
40
- const params = urlQueryToSearchParams(url.query);
41
- result = appendSearchParamsToUrl(result, params);
42
- }
43
- return result;
35
+ if (typeof url === "string") return url;
36
+ let result = url.pathname ?? "/";
37
+ if (url.query) {
38
+ const params = urlQueryToSearchParams(url.query);
39
+ result = appendSearchParamsToUrl(result, params);
40
+ }
41
+ return result;
44
42
  }
45
43
  /**
46
- * When `as` is provided, use it as the navigation target. This is a
47
- * simplification: Next.js keeps `url` and `as` as separate values (url for
48
- * data fetching, as for the browser URL). We collapse them because vinext's
49
- * navigateClient() fetches HTML from the target URL, so `as` must be a
50
- * server-resolvable path. Purely decorative `as` values are not supported.
51
- */
44
+ * When `as` is provided, use it as the navigation target. This is a
45
+ * simplification: Next.js keeps `url` and `as` as separate values (url for
46
+ * data fetching, as for the browser URL). We collapse them because vinext's
47
+ * navigateClient() fetches HTML from the target URL, so `as` must be a
48
+ * server-resolvable path. Purely decorative `as` values are not supported.
49
+ */
52
50
  function resolveNavigationTarget(url, as, locale) {
53
- return applyNavigationLocale(as ?? resolveUrl(url), locale);
51
+ return applyNavigationLocale(as ?? resolveUrl(url), locale);
54
52
  }
55
53
  function getDomainLocales() {
56
- return window.__NEXT_DATA__?.domainLocales;
54
+ return window.__NEXT_DATA__?.domainLocales;
57
55
  }
58
56
  function getCurrentHostname() {
59
- return window.location?.hostname;
57
+ return window.location?.hostname;
60
58
  }
61
59
  function getDomainLocalePath(url, locale) {
62
- return getDomainLocaleUrl(url, locale, {
63
- basePath: __basePath,
64
- currentHostname: getCurrentHostname(),
65
- domainItems: getDomainLocales(),
66
- });
60
+ return getDomainLocaleUrl(url, locale, {
61
+ basePath: __basePath,
62
+ currentHostname: getCurrentHostname(),
63
+ domainItems: getDomainLocales()
64
+ });
67
65
  }
68
66
  /**
69
- * Apply locale prefix to a URL for client-side navigation.
70
- * Same logic as Link's applyLocaleToHref but reads from window globals.
71
- */
72
- export function applyNavigationLocale(url, locale) {
73
- if (!locale || typeof window === "undefined")
74
- return url;
75
- // Absolute and protocol-relative URLs must not be prefixed — locale
76
- // only applies to local paths.
77
- if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//")) {
78
- return url;
79
- }
80
- const domainLocalePath = getDomainLocalePath(url, locale);
81
- if (domainLocalePath)
82
- return domainLocalePath;
83
- return addLocalePrefix(url, locale, window.__VINEXT_DEFAULT_LOCALE__ ?? "");
67
+ * Apply locale prefix to a URL for client-side navigation.
68
+ * Same logic as Link's applyLocaleToHref but reads from window globals.
69
+ */
70
+ function applyNavigationLocale(url, locale) {
71
+ if (!locale || typeof window === "undefined") return url;
72
+ if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("//")) return url;
73
+ const domainLocalePath = getDomainLocalePath(url, locale);
74
+ if (domainLocalePath) return domainLocalePath;
75
+ return addLocalePrefix(url, locale, window.__VINEXT_DEFAULT_LOCALE__ ?? "");
84
76
  }
85
77
  /** Check if a URL is external (any URL scheme per RFC 3986, or protocol-relative) */
86
- export function isExternalUrl(url) {
87
- return /^[a-z][a-z0-9+.-]*:/i.test(url) || url.startsWith("//");
78
+ function isExternalUrl(url) {
79
+ return /^[a-z][a-z0-9+.-]*:/i.test(url) || url.startsWith("//");
88
80
  }
89
81
  /** Resolve a hash URL to a basePath-stripped app URL for event payloads */
90
82
  function resolveHashUrl(url) {
91
- if (typeof window === "undefined")
92
- return url;
93
- if (url.startsWith("#"))
94
- return stripBasePath(window.location.pathname, __basePath) + window.location.search + url;
95
- // Full-path hash URL strip basePath for consistency with other events
96
- try {
97
- const parsed = new URL(url, window.location.href);
98
- return stripBasePath(parsed.pathname, __basePath) + parsed.search + parsed.hash;
99
- }
100
- catch {
101
- return url;
102
- }
83
+ if (typeof window === "undefined") return url;
84
+ if (url.startsWith("#")) return stripBasePath(window.location.pathname, __basePath) + window.location.search + url;
85
+ try {
86
+ const parsed = new URL(url, window.location.href);
87
+ return stripBasePath(parsed.pathname, __basePath) + parsed.search + parsed.hash;
88
+ } catch {
89
+ return url;
90
+ }
103
91
  }
104
92
  /** Check if a href is only a hash change relative to the current URL */
105
- export function isHashOnlyChange(href) {
106
- if (href.startsWith("#"))
107
- return true;
108
- if (typeof window === "undefined")
109
- return false;
110
- try {
111
- const current = new URL(window.location.href);
112
- const next = new URL(href, window.location.href);
113
- return current.pathname === next.pathname && current.search === next.search && next.hash !== "";
114
- }
115
- catch {
116
- return false;
117
- }
93
+ function isHashOnlyChange(href) {
94
+ if (href.startsWith("#")) return true;
95
+ if (typeof window === "undefined") return false;
96
+ try {
97
+ const current = new URL(window.location.href);
98
+ const next = new URL(href, window.location.href);
99
+ return current.pathname === next.pathname && current.search === next.search && next.hash !== "";
100
+ } catch {
101
+ return false;
102
+ }
118
103
  }
119
104
  /** Scroll to hash target element, or top if no hash */
120
105
  function scrollToHash(hash) {
121
- if (!hash || hash === "#") {
122
- window.scrollTo(0, 0);
123
- return;
124
- }
125
- const el = document.getElementById(hash.slice(1));
126
- if (el)
127
- el.scrollIntoView({ behavior: "auto" });
106
+ if (!hash || hash === "#") {
107
+ window.scrollTo(0, 0);
108
+ return;
109
+ }
110
+ const el = document.getElementById(hash.slice(1));
111
+ if (el) el.scrollIntoView({ behavior: "auto" });
128
112
  }
129
113
  /** Save current scroll position into history state for back/forward restoration */
130
114
  function saveScrollPosition() {
131
- const state = window.history.state ?? {};
132
- window.history.replaceState({ ...state, __vinext_scrollX: window.scrollX, __vinext_scrollY: window.scrollY }, "");
115
+ const state = window.history.state ?? {};
116
+ window.history.replaceState({
117
+ ...state,
118
+ __vinext_scrollX: window.scrollX,
119
+ __vinext_scrollY: window.scrollY
120
+ }, "");
133
121
  }
134
122
  /** Restore scroll position from history state */
135
123
  function restoreScrollPosition(state) {
136
- if (state && typeof state === "object" && "__vinext_scrollY" in state) {
137
- const { __vinext_scrollX: x, __vinext_scrollY: y } = state;
138
- requestAnimationFrame(() => window.scrollTo(x, y));
139
- }
124
+ if (state && typeof state === "object" && "__vinext_scrollY" in state) {
125
+ const { __vinext_scrollX: x, __vinext_scrollY: y } = state;
126
+ requestAnimationFrame(() => window.scrollTo(x, y));
127
+ }
140
128
  }
141
- // ---------------------------------------------------------------------------
142
- // Server-side SSR state uses a registration pattern so this module can be
143
- // bundled for the browser. The ALS-backed implementation lives in
144
- // router-state.ts (server-only) and registers itself on import.
145
- // ---------------------------------------------------------------------------
146
129
  let _ssrContext = null;
147
130
  let _getSSRContext = () => _ssrContext;
148
131
  let _setSSRContextImpl = (ctx) => {
149
- _ssrContext = ctx;
132
+ _ssrContext = ctx;
150
133
  };
151
134
  /**
152
- * Register ALS-backed state accessors. Called by router-state.ts on import.
153
- * @internal
154
- */
155
- export function _registerRouterStateAccessors(accessors) {
156
- _getSSRContext = accessors.getSSRContext;
157
- _setSSRContextImpl = accessors.setSSRContext;
135
+ * Register ALS-backed state accessors. Called by router-state.ts on import.
136
+ * @internal
137
+ */
138
+ function _registerRouterStateAccessors(accessors) {
139
+ _getSSRContext = accessors.getSSRContext;
140
+ _setSSRContextImpl = accessors.setSSRContext;
158
141
  }
159
- export function setSSRContext(ctx) {
160
- _setSSRContextImpl(ctx);
142
+ function setSSRContext(ctx) {
143
+ _setSSRContextImpl(ctx);
161
144
  }
162
145
  /**
163
- * Extract param names from a Next.js route pattern.
164
- * E.g., "/posts/[id]" → ["id"], "/docs/[...slug]" → ["slug"],
165
- * "/shop/[[...path]]" → ["path"], "/blog/[year]/[month]" → ["year", "month"]
166
- * Also handles internal format: "/posts/:id" → ["id"], "/docs/:slug+" → ["slug"]
167
- */
146
+ * Extract param names from a Next.js route pattern.
147
+ * E.g., "/posts/[id]" → ["id"], "/docs/[...slug]" → ["slug"],
148
+ * "/shop/[[...path]]" → ["path"], "/blog/[year]/[month]" → ["year", "month"]
149
+ * Also handles internal format: "/posts/:id" → ["id"], "/docs/:slug+" → ["slug"]
150
+ */
168
151
  function extractRouteParamNames(pattern) {
169
- const names = [];
170
- // Match Next.js bracket format: [id], [...slug], [[...slug]]
171
- const bracketMatches = pattern.matchAll(/\[{1,2}(?:\.\.\.)?([\w-]+)\]{1,2}/g);
172
- for (const m of bracketMatches) {
173
- names.push(m[1]);
174
- }
175
- if (names.length > 0)
176
- return names;
177
- // Fallback: match internal :param format
178
- const colonMatches = pattern.matchAll(/:([\w-]+)[+*]?/g);
179
- for (const m of colonMatches) {
180
- names.push(m[1]);
181
- }
182
- return names;
152
+ const names = [];
153
+ const bracketMatches = pattern.matchAll(/\[{1,2}(?:\.\.\.)?([\w-]+)\]{1,2}/g);
154
+ for (const m of bracketMatches) names.push(m[1]);
155
+ if (names.length > 0) return names;
156
+ const colonMatches = pattern.matchAll(/:([\w-]+)[+*]?/g);
157
+ for (const m of colonMatches) names.push(m[1]);
158
+ return names;
183
159
  }
184
160
  function getPathnameAndQuery() {
185
- if (typeof window === "undefined") {
186
- const _ssrCtx = _getSSRContext();
187
- if (_ssrCtx) {
188
- const query = {};
189
- for (const [key, value] of Object.entries(_ssrCtx.query)) {
190
- query[key] = Array.isArray(value) ? [...value] : value;
191
- }
192
- return { pathname: _ssrCtx.pathname, query, asPath: _ssrCtx.asPath };
193
- }
194
- return { pathname: "/", query: {}, asPath: "/" };
195
- }
196
- const resolvedPath = stripBasePath(window.location.pathname, __basePath);
197
- // In Next.js, router.pathname is the route pattern (e.g., "/posts/[id]"),
198
- // not the resolved path ("/posts/42"). __NEXT_DATA__.page holds the route
199
- // pattern and is updated by navigateClient() on every client-side navigation.
200
- const pathname = window.__NEXT_DATA__?.page ?? resolvedPath;
201
- const routeQuery = {};
202
- // Include dynamic route params from __NEXT_DATA__ (e.g., { id: "42" } from /posts/[id]).
203
- // Only include keys that are part of the route pattern (not stale query params).
204
- const nextData = window.__NEXT_DATA__;
205
- if (nextData && nextData.query && nextData.page) {
206
- const routeParamNames = extractRouteParamNames(nextData.page);
207
- for (const key of routeParamNames) {
208
- const value = nextData.query[key];
209
- if (typeof value === "string") {
210
- routeQuery[key] = value;
211
- }
212
- else if (Array.isArray(value)) {
213
- routeQuery[key] = [...value];
214
- }
215
- }
216
- }
217
- // URL search params always reflect the current URL
218
- const searchQuery = {};
219
- const params = new URLSearchParams(window.location.search);
220
- for (const [key, value] of params) {
221
- addQueryParam(searchQuery, key, value);
222
- }
223
- const query = { ...searchQuery, ...routeQuery };
224
- // asPath uses the resolved browser path, not the route pattern
225
- const asPath = resolvedPath + window.location.search + window.location.hash;
226
- return { pathname, query, asPath };
161
+ if (typeof window === "undefined") {
162
+ const _ssrCtx = _getSSRContext();
163
+ if (_ssrCtx) {
164
+ const query = {};
165
+ for (const [key, value] of Object.entries(_ssrCtx.query)) query[key] = Array.isArray(value) ? [...value] : value;
166
+ return {
167
+ pathname: _ssrCtx.pathname,
168
+ query,
169
+ asPath: _ssrCtx.asPath
170
+ };
171
+ }
172
+ return {
173
+ pathname: "/",
174
+ query: {},
175
+ asPath: "/"
176
+ };
177
+ }
178
+ const resolvedPath = stripBasePath(window.location.pathname, __basePath);
179
+ const pathname = window.__NEXT_DATA__?.page ?? resolvedPath;
180
+ const routeQuery = {};
181
+ const nextData = window.__NEXT_DATA__;
182
+ if (nextData && nextData.query && nextData.page) {
183
+ const routeParamNames = extractRouteParamNames(nextData.page);
184
+ for (const key of routeParamNames) {
185
+ const value = nextData.query[key];
186
+ if (typeof value === "string") routeQuery[key] = value;
187
+ else if (Array.isArray(value)) routeQuery[key] = [...value];
188
+ }
189
+ }
190
+ const searchQuery = {};
191
+ const params = new URLSearchParams(window.location.search);
192
+ for (const [key, value] of params) addQueryParam(searchQuery, key, value);
193
+ return {
194
+ pathname,
195
+ query: {
196
+ ...searchQuery,
197
+ ...routeQuery
198
+ },
199
+ asPath: resolvedPath + window.location.search + window.location.hash
200
+ };
227
201
  }
228
202
  /**
229
- * Perform client-side navigation: fetch the target page's HTML,
230
- * extract __NEXT_DATA__, and re-render the React root.
231
- */
203
+ * Perform client-side navigation: fetch the target page's HTML,
204
+ * extract __NEXT_DATA__, and re-render the React root.
205
+ */
232
206
  let _navInProgress = false;
233
207
  async function navigateClient(url) {
234
- if (typeof window === "undefined")
235
- return;
236
- const root = window.__VINEXT_ROOT__;
237
- if (!root) {
238
- // No React root yet — fall back to hard navigation
239
- window.location.href = url;
240
- return;
241
- }
242
- // Prevent re-entrant navigation (e.g., double popstate events)
243
- if (_navInProgress)
244
- return;
245
- _navInProgress = true;
246
- try {
247
- // Fetch the target page's SSR HTML
248
- const res = await fetch(url, { headers: { Accept: "text/html" } });
249
- if (!res.ok) {
250
- window.location.href = url;
251
- return;
252
- }
253
- const html = await res.text();
254
- // Extract __NEXT_DATA__ from the HTML
255
- const match = html.match(/<script>window\.__NEXT_DATA__\s*=\s*(.*?)<\/script>/);
256
- if (!match) {
257
- window.location.href = url;
258
- return;
259
- }
260
- const nextData = JSON.parse(match[1]);
261
- const { pageProps } = nextData.props;
262
- window.__NEXT_DATA__ = nextData;
263
- // Get the page module URL from __NEXT_DATA__.__vinext (preferred),
264
- // or fall back to parsing the hydration script
265
- let pageModuleUrl = nextData.__vinext?.pageModuleUrl;
266
- if (!pageModuleUrl) {
267
- // Legacy fallback: try to find the module URL in the inline script
268
- const moduleMatch = html.match(/import\("([^"]+)"\);\s*\n\s*const PageComponent/);
269
- const altMatch = html.match(/await import\("([^"]+pages\/[^"]+)"\)/);
270
- pageModuleUrl = moduleMatch?.[1] ?? altMatch?.[1] ?? undefined;
271
- }
272
- if (!pageModuleUrl) {
273
- window.location.href = url;
274
- return;
275
- }
276
- // Validate the module URL before importing — defense-in-depth against
277
- // unexpected __NEXT_DATA__ or malformed HTML responses
278
- if (!isValidModulePath(pageModuleUrl)) {
279
- console.error("[vinext] Blocked import of invalid page module path:", pageModuleUrl);
280
- window.location.href = url;
281
- return;
282
- }
283
- // Dynamically import the new page module
284
- const pageModule = await import(/* @vite-ignore */ pageModuleUrl);
285
- const PageComponent = pageModule.default;
286
- if (!PageComponent) {
287
- window.location.href = url;
288
- return;
289
- }
290
- // Import React for createElement
291
- const React = (await import("react")).default;
292
- // Re-render with the new page, loading _app if needed
293
- let AppComponent = window.__VINEXT_APP__;
294
- const appModuleUrl = nextData.__vinext?.appModuleUrl;
295
- if (!AppComponent && appModuleUrl) {
296
- if (!isValidModulePath(appModuleUrl)) {
297
- console.error("[vinext] Blocked import of invalid app module path:", appModuleUrl);
298
- }
299
- else {
300
- try {
301
- const appModule = await import(/* @vite-ignore */ appModuleUrl);
302
- AppComponent = appModule.default;
303
- window.__VINEXT_APP__ = AppComponent;
304
- }
305
- catch {
306
- // _app not available — continue without it
307
- }
308
- }
309
- }
310
- let element;
311
- if (AppComponent) {
312
- element = React.createElement(AppComponent, {
313
- Component: PageComponent,
314
- pageProps,
315
- });
316
- }
317
- else {
318
- element = React.createElement(PageComponent, pageProps);
319
- }
320
- // Wrap with RouterContext.Provider so next/compat/router works
321
- element = wrapWithRouterContext(element);
322
- root.render(element);
323
- }
324
- catch (err) {
325
- console.error("[vinext] Client navigation failed:", err);
326
- routerEvents.emit("routeChangeError", err, url, { shallow: false });
327
- window.location.href = url;
328
- }
329
- finally {
330
- _navInProgress = false;
331
- }
208
+ if (typeof window === "undefined") return;
209
+ const root = window.__VINEXT_ROOT__;
210
+ if (!root) {
211
+ window.location.href = url;
212
+ return;
213
+ }
214
+ if (_navInProgress) return;
215
+ _navInProgress = true;
216
+ try {
217
+ const res = await fetch(url, { headers: { Accept: "text/html" } });
218
+ if (!res.ok) {
219
+ window.location.href = url;
220
+ return;
221
+ }
222
+ const html = await res.text();
223
+ const match = html.match(/<script>window\.__NEXT_DATA__\s*=\s*(.*?)<\/script>/);
224
+ if (!match) {
225
+ window.location.href = url;
226
+ return;
227
+ }
228
+ const nextData = JSON.parse(match[1]);
229
+ const { pageProps } = nextData.props;
230
+ window.__NEXT_DATA__ = nextData;
231
+ let pageModuleUrl = nextData.__vinext?.pageModuleUrl;
232
+ if (!pageModuleUrl) {
233
+ const moduleMatch = html.match(/import\("([^"]+)"\);\s*\n\s*const PageComponent/);
234
+ const altMatch = html.match(/await import\("([^"]+pages\/[^"]+)"\)/);
235
+ pageModuleUrl = moduleMatch?.[1] ?? altMatch?.[1] ?? void 0;
236
+ }
237
+ if (!pageModuleUrl) {
238
+ window.location.href = url;
239
+ return;
240
+ }
241
+ if (!isValidModulePath(pageModuleUrl)) {
242
+ console.error("[vinext] Blocked import of invalid page module path:", pageModuleUrl);
243
+ window.location.href = url;
244
+ return;
245
+ }
246
+ const PageComponent = (await import(
247
+ /* @vite-ignore */
248
+ pageModuleUrl
249
+ )).default;
250
+ if (!PageComponent) {
251
+ window.location.href = url;
252
+ return;
253
+ }
254
+ const React = (await import("react")).default;
255
+ let AppComponent = window.__VINEXT_APP__;
256
+ const appModuleUrl = nextData.__vinext?.appModuleUrl;
257
+ if (!AppComponent && appModuleUrl) if (!isValidModulePath(appModuleUrl)) console.error("[vinext] Blocked import of invalid app module path:", appModuleUrl);
258
+ else try {
259
+ AppComponent = (await import(
260
+ /* @vite-ignore */
261
+ appModuleUrl
262
+ )).default;
263
+ window.__VINEXT_APP__ = AppComponent;
264
+ } catch {}
265
+ let element;
266
+ if (AppComponent) element = React.createElement(AppComponent, {
267
+ Component: PageComponent,
268
+ pageProps
269
+ });
270
+ else element = React.createElement(PageComponent, pageProps);
271
+ element = wrapWithRouterContext(element);
272
+ root.render(element);
273
+ } catch (err) {
274
+ console.error("[vinext] Client navigation failed:", err);
275
+ routerEvents.emit("routeChangeError", err, url, { shallow: false });
276
+ window.location.href = url;
277
+ } finally {
278
+ _navInProgress = false;
279
+ }
332
280
  }
333
281
  /**
334
- * Build the full router value object from the current pathname, query, asPath,
335
- * and a set of navigation methods. Shared by useRouter() (which passes
336
- * hook-derived callbacks) and wrapWithRouterContext() (which passes the Router
337
- * singleton methods) so the shape stays in sync.
338
- */
282
+ * Build the full router value object from the current pathname, query, asPath,
283
+ * and a set of navigation methods. Shared by useRouter() (which passes
284
+ * hook-derived callbacks) and wrapWithRouterContext() (which passes the Router
285
+ * singleton methods) so the shape stays in sync.
286
+ */
339
287
  function buildRouterValue(pathname, query, asPath, methods) {
340
- const _ssrState = _getSSRContext();
341
- const nextData = typeof window !== "undefined"
342
- ? window.__NEXT_DATA__
343
- : undefined;
344
- const locale = typeof window === "undefined" ? _ssrState?.locale : window.__VINEXT_LOCALE__;
345
- const locales = typeof window === "undefined" ? _ssrState?.locales : window.__VINEXT_LOCALES__;
346
- const defaultLocale = typeof window === "undefined" ? _ssrState?.defaultLocale : window.__VINEXT_DEFAULT_LOCALE__;
347
- const domainLocales = typeof window === "undefined" ? _ssrState?.domainLocales : nextData?.domainLocales;
348
- const route = typeof window !== "undefined" ? (nextData?.page ?? pathname) : pathname;
349
- return {
350
- pathname,
351
- route,
352
- query,
353
- asPath,
354
- basePath: __basePath,
355
- locale,
356
- locales,
357
- defaultLocale,
358
- domainLocales,
359
- isReady: true,
360
- isPreview: false,
361
- isFallback: typeof window !== "undefined" && nextData?.isFallback === true,
362
- ...methods,
363
- events: routerEvents,
364
- };
288
+ const _ssrState = _getSSRContext();
289
+ const nextData = typeof window !== "undefined" ? window.__NEXT_DATA__ : void 0;
290
+ const locale = typeof window === "undefined" ? _ssrState?.locale : window.__VINEXT_LOCALE__;
291
+ const locales = typeof window === "undefined" ? _ssrState?.locales : window.__VINEXT_LOCALES__;
292
+ const defaultLocale = typeof window === "undefined" ? _ssrState?.defaultLocale : window.__VINEXT_DEFAULT_LOCALE__;
293
+ const domainLocales = typeof window === "undefined" ? _ssrState?.domainLocales : nextData?.domainLocales;
294
+ return {
295
+ pathname,
296
+ route: typeof window !== "undefined" ? nextData?.page ?? pathname : pathname,
297
+ query,
298
+ asPath,
299
+ basePath: __basePath,
300
+ locale,
301
+ locales,
302
+ defaultLocale,
303
+ domainLocales,
304
+ isReady: true,
305
+ isPreview: false,
306
+ isFallback: typeof window !== "undefined" && nextData?.isFallback === true,
307
+ ...methods,
308
+ events: routerEvents
309
+ };
365
310
  }
366
311
  /**
367
- * useRouter hook - Pages Router compatible.
368
- */
369
- export function useRouter() {
370
- const [{ pathname, query, asPath }, setState] = useState(getPathnameAndQuery);
371
- // Popstate is handled by the module-level listener below so beforePopState()
372
- // is consistently enforced even when multiple components mount useRouter().
373
- useEffect(() => {
374
- const onNavigate = ((_e) => {
375
- setState(getPathnameAndQuery());
376
- });
377
- window.addEventListener("vinext:navigate", onNavigate);
378
- return () => window.removeEventListener("vinext:navigate", onNavigate);
379
- }, []);
380
- const push = useCallback(async (url, as, options) => {
381
- let resolved = resolveNavigationTarget(url, as, options?.locale);
382
- // External URLs delegate to browser (unless same-origin)
383
- if (isExternalUrl(resolved)) {
384
- const localPath = toSameOriginAppPath(resolved, __basePath);
385
- if (localPath == null) {
386
- window.location.assign(resolved);
387
- return true;
388
- }
389
- resolved = localPath;
390
- }
391
- const full = toBrowserNavigationHref(resolved, window.location.href, __basePath);
392
- // Hash-only change no page fetch needed
393
- if (isHashOnlyChange(resolved)) {
394
- const eventUrl = resolveHashUrl(resolved);
395
- routerEvents.emit("hashChangeStart", eventUrl, {
396
- shallow: options?.shallow ?? false,
397
- });
398
- const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
399
- window.history.pushState({}, "", resolved.startsWith("#") ? resolved : full);
400
- _lastPathnameAndSearch = window.location.pathname + window.location.search;
401
- scrollToHash(hash);
402
- setState(getPathnameAndQuery());
403
- routerEvents.emit("hashChangeComplete", eventUrl, {
404
- shallow: options?.shallow ?? false,
405
- });
406
- window.dispatchEvent(new CustomEvent("vinext:navigate"));
407
- return true;
408
- }
409
- saveScrollPosition();
410
- routerEvents.emit("routeChangeStart", resolved, { shallow: options?.shallow ?? false });
411
- routerEvents.emit("beforeHistoryChange", resolved, { shallow: options?.shallow ?? false });
412
- window.history.pushState({}, "", full);
413
- _lastPathnameAndSearch = window.location.pathname + window.location.search;
414
- if (!options?.shallow) {
415
- await navigateClient(full);
416
- }
417
- setState(getPathnameAndQuery());
418
- routerEvents.emit("routeChangeComplete", resolved, { shallow: options?.shallow ?? false });
419
- // Scroll: handle hash target, else scroll to top unless scroll:false
420
- const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
421
- if (hash) {
422
- scrollToHash(hash);
423
- }
424
- else if (options?.scroll !== false) {
425
- window.scrollTo(0, 0);
426
- }
427
- window.dispatchEvent(new CustomEvent("vinext:navigate"));
428
- return true;
429
- }, []);
430
- const replace = useCallback(async (url, as, options) => {
431
- let resolved = resolveNavigationTarget(url, as, options?.locale);
432
- // External URLs — delegate to browser (unless same-origin)
433
- if (isExternalUrl(resolved)) {
434
- const localPath = toSameOriginAppPath(resolved, __basePath);
435
- if (localPath == null) {
436
- window.location.replace(resolved);
437
- return true;
438
- }
439
- resolved = localPath;
440
- }
441
- const full = toBrowserNavigationHref(resolved, window.location.href, __basePath);
442
- // Hash-only change — no page fetch needed
443
- if (isHashOnlyChange(resolved)) {
444
- const eventUrl = resolveHashUrl(resolved);
445
- routerEvents.emit("hashChangeStart", eventUrl, {
446
- shallow: options?.shallow ?? false,
447
- });
448
- const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
449
- window.history.replaceState({}, "", resolved.startsWith("#") ? resolved : full);
450
- _lastPathnameAndSearch = window.location.pathname + window.location.search;
451
- scrollToHash(hash);
452
- setState(getPathnameAndQuery());
453
- routerEvents.emit("hashChangeComplete", eventUrl, {
454
- shallow: options?.shallow ?? false,
455
- });
456
- window.dispatchEvent(new CustomEvent("vinext:navigate"));
457
- return true;
458
- }
459
- routerEvents.emit("routeChangeStart", resolved, { shallow: options?.shallow ?? false });
460
- routerEvents.emit("beforeHistoryChange", resolved, { shallow: options?.shallow ?? false });
461
- window.history.replaceState({}, "", full);
462
- _lastPathnameAndSearch = window.location.pathname + window.location.search;
463
- if (!options?.shallow) {
464
- await navigateClient(full);
465
- }
466
- setState(getPathnameAndQuery());
467
- routerEvents.emit("routeChangeComplete", resolved, { shallow: options?.shallow ?? false });
468
- // Scroll: handle hash target, else scroll to top unless scroll:false
469
- const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
470
- if (hash) {
471
- scrollToHash(hash);
472
- }
473
- else if (options?.scroll !== false) {
474
- window.scrollTo(0, 0);
475
- }
476
- window.dispatchEvent(new CustomEvent("vinext:navigate"));
477
- return true;
478
- }, []);
479
- const back = useCallback(() => {
480
- window.history.back();
481
- }, []);
482
- const reload = useCallback(() => {
483
- window.location.reload();
484
- }, []);
485
- const prefetch = useCallback(async (url) => {
486
- // Inject a <link rel="prefetch"> for the target page
487
- if (typeof document !== "undefined") {
488
- const link = document.createElement("link");
489
- link.rel = "prefetch";
490
- link.href = url;
491
- link.as = "document";
492
- document.head.appendChild(link);
493
- }
494
- }, []);
495
- const router = useMemo(() => buildRouterValue(pathname, query, asPath, {
496
- push,
497
- replace,
498
- back,
499
- reload,
500
- prefetch,
501
- beforePopState: (cb) => {
502
- _beforePopStateCb = cb;
503
- },
504
- }), [pathname, query, asPath, push, replace, back, reload, prefetch]);
505
- return router;
312
+ * useRouter hook - Pages Router compatible.
313
+ */
314
+ function useRouter() {
315
+ const [{ pathname, query, asPath }, setState] = useState(getPathnameAndQuery);
316
+ useEffect(() => {
317
+ const onNavigate = ((_e) => {
318
+ setState(getPathnameAndQuery());
319
+ });
320
+ window.addEventListener("vinext:navigate", onNavigate);
321
+ return () => window.removeEventListener("vinext:navigate", onNavigate);
322
+ }, []);
323
+ const push = useCallback(async (url, as, options) => {
324
+ let resolved = resolveNavigationTarget(url, as, options?.locale);
325
+ if (isExternalUrl(resolved)) {
326
+ const localPath = toSameOriginAppPath(resolved, __basePath);
327
+ if (localPath == null) {
328
+ window.location.assign(resolved);
329
+ return true;
330
+ }
331
+ resolved = localPath;
332
+ }
333
+ const full = toBrowserNavigationHref(resolved, window.location.href, __basePath);
334
+ if (isHashOnlyChange(resolved)) {
335
+ const eventUrl = resolveHashUrl(resolved);
336
+ routerEvents.emit("hashChangeStart", eventUrl, { shallow: options?.shallow ?? false });
337
+ const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
338
+ window.history.pushState({}, "", resolved.startsWith("#") ? resolved : full);
339
+ _lastPathnameAndSearch = window.location.pathname + window.location.search;
340
+ scrollToHash(hash);
341
+ setState(getPathnameAndQuery());
342
+ routerEvents.emit("hashChangeComplete", eventUrl, { shallow: options?.shallow ?? false });
343
+ window.dispatchEvent(new CustomEvent("vinext:navigate"));
344
+ return true;
345
+ }
346
+ saveScrollPosition();
347
+ routerEvents.emit("routeChangeStart", resolved, { shallow: options?.shallow ?? false });
348
+ routerEvents.emit("beforeHistoryChange", resolved, { shallow: options?.shallow ?? false });
349
+ window.history.pushState({}, "", full);
350
+ _lastPathnameAndSearch = window.location.pathname + window.location.search;
351
+ if (!options?.shallow) await navigateClient(full);
352
+ setState(getPathnameAndQuery());
353
+ routerEvents.emit("routeChangeComplete", resolved, { shallow: options?.shallow ?? false });
354
+ const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
355
+ if (hash) scrollToHash(hash);
356
+ else if (options?.scroll !== false) window.scrollTo(0, 0);
357
+ window.dispatchEvent(new CustomEvent("vinext:navigate"));
358
+ return true;
359
+ }, []);
360
+ const replace = useCallback(async (url, as, options) => {
361
+ let resolved = resolveNavigationTarget(url, as, options?.locale);
362
+ if (isExternalUrl(resolved)) {
363
+ const localPath = toSameOriginAppPath(resolved, __basePath);
364
+ if (localPath == null) {
365
+ window.location.replace(resolved);
366
+ return true;
367
+ }
368
+ resolved = localPath;
369
+ }
370
+ const full = toBrowserNavigationHref(resolved, window.location.href, __basePath);
371
+ if (isHashOnlyChange(resolved)) {
372
+ const eventUrl = resolveHashUrl(resolved);
373
+ routerEvents.emit("hashChangeStart", eventUrl, { shallow: options?.shallow ?? false });
374
+ const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
375
+ window.history.replaceState({}, "", resolved.startsWith("#") ? resolved : full);
376
+ _lastPathnameAndSearch = window.location.pathname + window.location.search;
377
+ scrollToHash(hash);
378
+ setState(getPathnameAndQuery());
379
+ routerEvents.emit("hashChangeComplete", eventUrl, { shallow: options?.shallow ?? false });
380
+ window.dispatchEvent(new CustomEvent("vinext:navigate"));
381
+ return true;
382
+ }
383
+ routerEvents.emit("routeChangeStart", resolved, { shallow: options?.shallow ?? false });
384
+ routerEvents.emit("beforeHistoryChange", resolved, { shallow: options?.shallow ?? false });
385
+ window.history.replaceState({}, "", full);
386
+ _lastPathnameAndSearch = window.location.pathname + window.location.search;
387
+ if (!options?.shallow) await navigateClient(full);
388
+ setState(getPathnameAndQuery());
389
+ routerEvents.emit("routeChangeComplete", resolved, { shallow: options?.shallow ?? false });
390
+ const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
391
+ if (hash) scrollToHash(hash);
392
+ else if (options?.scroll !== false) window.scrollTo(0, 0);
393
+ window.dispatchEvent(new CustomEvent("vinext:navigate"));
394
+ return true;
395
+ }, []);
396
+ const back = useCallback(() => {
397
+ window.history.back();
398
+ }, []);
399
+ const reload = useCallback(() => {
400
+ window.location.reload();
401
+ }, []);
402
+ const prefetch = useCallback(async (url) => {
403
+ if (typeof document !== "undefined") {
404
+ const link = document.createElement("link");
405
+ link.rel = "prefetch";
406
+ link.href = url;
407
+ link.as = "document";
408
+ document.head.appendChild(link);
409
+ }
410
+ }, []);
411
+ return useMemo(() => buildRouterValue(pathname, query, asPath, {
412
+ push,
413
+ replace,
414
+ back,
415
+ reload,
416
+ prefetch,
417
+ beforePopState: (cb) => {
418
+ _beforePopStateCb = cb;
419
+ }
420
+ }), [
421
+ pathname,
422
+ query,
423
+ asPath,
424
+ push,
425
+ replace,
426
+ back,
427
+ reload,
428
+ prefetch
429
+ ]);
506
430
  }
507
- // beforePopState callback: called before handling browser back/forward.
508
- // If it returns false, the navigation is cancelled.
509
431
  let _beforePopStateCb;
510
- // Track pathname+search for detecting hash-only back/forward in the popstate
511
- // handler. Updated after every pushState/replaceState so that popstate can
512
- // compare the previous value with the (already-changed) window.location.
513
432
  let _lastPathnameAndSearch = typeof window !== "undefined" ? window.location.pathname + window.location.search : "";
514
- // Module-level popstate listener: handles browser back/forward by re-rendering
515
- // the React root with the page at the new URL. This runs regardless of whether
516
- // any component calls useRouter().
517
- if (typeof window !== "undefined") {
518
- window.addEventListener("popstate", (e) => {
519
- const browserUrl = window.location.pathname + window.location.search;
520
- const appUrl = stripBasePath(window.location.pathname, __basePath) + window.location.search;
521
- // Detect hash-only back/forward: pathname+search unchanged, only hash differs.
522
- const isHashOnly = browserUrl === _lastPathnameAndSearch;
523
- // Check beforePopState callback
524
- if (_beforePopStateCb !== undefined) {
525
- const shouldContinue = _beforePopStateCb({
526
- url: appUrl,
527
- as: appUrl,
528
- options: { shallow: false },
529
- });
530
- if (!shouldContinue)
531
- return;
532
- }
533
- // Update tracker only after beforePopState confirms navigation proceeds.
534
- // If beforePopState cancels, the tracker must retain the previous value
535
- // so the next popstate compares against the correct baseline.
536
- _lastPathnameAndSearch = browserUrl;
537
- if (isHashOnly) {
538
- // Hash-only back/forward no page fetch needed
539
- const hashUrl = appUrl + window.location.hash;
540
- routerEvents.emit("hashChangeStart", hashUrl, { shallow: false });
541
- scrollToHash(window.location.hash);
542
- routerEvents.emit("hashChangeComplete", hashUrl, { shallow: false });
543
- window.dispatchEvent(new CustomEvent("vinext:navigate"));
544
- return;
545
- }
546
- const fullAppUrl = appUrl + window.location.hash;
547
- routerEvents.emit("routeChangeStart", fullAppUrl, { shallow: false });
548
- // Note: The browser has already updated window.location by the time popstate
549
- // fires, so this is not truly "before" the URL change. In Next.js the popstate
550
- // handler calls replaceState to store history metadata — beforeHistoryChange
551
- // precedes that call, not the URL change itself. We emit it here for API
552
- // compatibility.
553
- routerEvents.emit("beforeHistoryChange", fullAppUrl, { shallow: false });
554
- void navigateClient(browserUrl).then(() => {
555
- routerEvents.emit("routeChangeComplete", fullAppUrl, { shallow: false });
556
- restoreScrollPosition(e.state);
557
- window.dispatchEvent(new CustomEvent("vinext:navigate"));
558
- });
559
- });
560
- }
433
+ if (typeof window !== "undefined") window.addEventListener("popstate", (e) => {
434
+ const browserUrl = window.location.pathname + window.location.search;
435
+ const appUrl = stripBasePath(window.location.pathname, __basePath) + window.location.search;
436
+ const isHashOnly = browserUrl === _lastPathnameAndSearch;
437
+ if (_beforePopStateCb !== void 0) {
438
+ if (!_beforePopStateCb({
439
+ url: appUrl,
440
+ as: appUrl,
441
+ options: { shallow: false }
442
+ })) return;
443
+ }
444
+ _lastPathnameAndSearch = browserUrl;
445
+ if (isHashOnly) {
446
+ const hashUrl = appUrl + window.location.hash;
447
+ routerEvents.emit("hashChangeStart", hashUrl, { shallow: false });
448
+ scrollToHash(window.location.hash);
449
+ routerEvents.emit("hashChangeComplete", hashUrl, { shallow: false });
450
+ window.dispatchEvent(new CustomEvent("vinext:navigate"));
451
+ return;
452
+ }
453
+ const fullAppUrl = appUrl + window.location.hash;
454
+ routerEvents.emit("routeChangeStart", fullAppUrl, { shallow: false });
455
+ routerEvents.emit("beforeHistoryChange", fullAppUrl, { shallow: false });
456
+ navigateClient(browserUrl).then(() => {
457
+ routerEvents.emit("routeChangeComplete", fullAppUrl, { shallow: false });
458
+ restoreScrollPosition(e.state);
459
+ window.dispatchEvent(new CustomEvent("vinext:navigate"));
460
+ });
461
+ });
561
462
  /**
562
- * Wrap a React element in a RouterContext.Provider so that
563
- * next/compat/router's useRouter() returns the real Pages Router value.
564
- *
565
- * This is a plain function, NOT a React component — it builds the router
566
- * value object directly from the current SSR context (server) or
567
- * window.location + Router singleton (client), avoiding duplicate state
568
- * that a hook-based component would create.
569
- */
570
- export function wrapWithRouterContext(element) {
571
- const { pathname, query, asPath } = getPathnameAndQuery();
572
- const routerValue = buildRouterValue(pathname, query, asPath, {
573
- push: Router.push,
574
- replace: Router.replace,
575
- back: Router.back,
576
- reload: Router.reload,
577
- prefetch: Router.prefetch,
578
- beforePopState: Router.beforePopState,
579
- });
580
- return createElement(RouterContext.Provider, { value: routerValue }, element);
463
+ * Wrap a React element in a RouterContext.Provider so that
464
+ * next/compat/router's useRouter() returns the real Pages Router value.
465
+ *
466
+ * This is a plain function, NOT a React component — it builds the router
467
+ * value object directly from the current SSR context (server) or
468
+ * window.location + Router singleton (client), avoiding duplicate state
469
+ * that a hook-based component would create.
470
+ */
471
+ function wrapWithRouterContext(element) {
472
+ const { pathname, query, asPath } = getPathnameAndQuery();
473
+ const routerValue = buildRouterValue(pathname, query, asPath, {
474
+ push: Router.push,
475
+ replace: Router.replace,
476
+ back: Router.back,
477
+ reload: Router.reload,
478
+ prefetch: Router.prefetch,
479
+ beforePopState: Router.beforePopState
480
+ });
481
+ return createElement(RouterContext.Provider, { value: routerValue }, element);
581
482
  }
582
- // Also export a default Router singleton for `import Router from 'next/router'`
583
483
  const Router = {
584
- push: async (url, as, options) => {
585
- let resolved = resolveNavigationTarget(url, as, options?.locale);
586
- // External URLs (unless same-origin)
587
- if (isExternalUrl(resolved)) {
588
- const localPath = toSameOriginAppPath(resolved, __basePath);
589
- if (localPath == null) {
590
- window.location.assign(resolved);
591
- return true;
592
- }
593
- resolved = localPath;
594
- }
595
- const full = toBrowserNavigationHref(resolved, window.location.href, __basePath);
596
- // Hash-only change
597
- if (isHashOnlyChange(resolved)) {
598
- const eventUrl = resolveHashUrl(resolved);
599
- routerEvents.emit("hashChangeStart", eventUrl, {
600
- shallow: options?.shallow ?? false,
601
- });
602
- const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
603
- window.history.pushState({}, "", resolved.startsWith("#") ? resolved : full);
604
- _lastPathnameAndSearch = window.location.pathname + window.location.search;
605
- scrollToHash(hash);
606
- routerEvents.emit("hashChangeComplete", eventUrl, {
607
- shallow: options?.shallow ?? false,
608
- });
609
- window.dispatchEvent(new CustomEvent("vinext:navigate"));
610
- return true;
611
- }
612
- saveScrollPosition();
613
- routerEvents.emit("routeChangeStart", resolved, { shallow: options?.shallow ?? false });
614
- routerEvents.emit("beforeHistoryChange", resolved, { shallow: options?.shallow ?? false });
615
- window.history.pushState({}, "", full);
616
- _lastPathnameAndSearch = window.location.pathname + window.location.search;
617
- if (!options?.shallow) {
618
- await navigateClient(full);
619
- }
620
- routerEvents.emit("routeChangeComplete", resolved, { shallow: options?.shallow ?? false });
621
- const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
622
- if (hash) {
623
- scrollToHash(hash);
624
- }
625
- else if (options?.scroll !== false) {
626
- window.scrollTo(0, 0);
627
- }
628
- window.dispatchEvent(new CustomEvent("vinext:navigate"));
629
- return true;
630
- },
631
- replace: async (url, as, options) => {
632
- let resolved = resolveNavigationTarget(url, as, options?.locale);
633
- // External URLs (unless same-origin)
634
- if (isExternalUrl(resolved)) {
635
- const localPath = toSameOriginAppPath(resolved, __basePath);
636
- if (localPath == null) {
637
- window.location.replace(resolved);
638
- return true;
639
- }
640
- resolved = localPath;
641
- }
642
- const full = toBrowserNavigationHref(resolved, window.location.href, __basePath);
643
- // Hash-only change
644
- if (isHashOnlyChange(resolved)) {
645
- const eventUrl = resolveHashUrl(resolved);
646
- routerEvents.emit("hashChangeStart", eventUrl, {
647
- shallow: options?.shallow ?? false,
648
- });
649
- const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
650
- window.history.replaceState({}, "", resolved.startsWith("#") ? resolved : full);
651
- _lastPathnameAndSearch = window.location.pathname + window.location.search;
652
- scrollToHash(hash);
653
- routerEvents.emit("hashChangeComplete", eventUrl, {
654
- shallow: options?.shallow ?? false,
655
- });
656
- window.dispatchEvent(new CustomEvent("vinext:navigate"));
657
- return true;
658
- }
659
- routerEvents.emit("routeChangeStart", resolved, { shallow: options?.shallow ?? false });
660
- routerEvents.emit("beforeHistoryChange", resolved, { shallow: options?.shallow ?? false });
661
- window.history.replaceState({}, "", full);
662
- _lastPathnameAndSearch = window.location.pathname + window.location.search;
663
- if (!options?.shallow) {
664
- await navigateClient(full);
665
- }
666
- routerEvents.emit("routeChangeComplete", resolved, { shallow: options?.shallow ?? false });
667
- const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
668
- if (hash) {
669
- scrollToHash(hash);
670
- }
671
- else if (options?.scroll !== false) {
672
- window.scrollTo(0, 0);
673
- }
674
- window.dispatchEvent(new CustomEvent("vinext:navigate"));
675
- return true;
676
- },
677
- back: () => window.history.back(),
678
- reload: () => window.location.reload(),
679
- prefetch: async (url) => {
680
- if (typeof document !== "undefined") {
681
- const link = document.createElement("link");
682
- link.rel = "prefetch";
683
- link.href = url;
684
- link.as = "document";
685
- document.head.appendChild(link);
686
- }
687
- },
688
- beforePopState: (cb) => {
689
- _beforePopStateCb = cb;
690
- },
691
- events: routerEvents,
484
+ push: async (url, as, options) => {
485
+ let resolved = resolveNavigationTarget(url, as, options?.locale);
486
+ if (isExternalUrl(resolved)) {
487
+ const localPath = toSameOriginAppPath(resolved, __basePath);
488
+ if (localPath == null) {
489
+ window.location.assign(resolved);
490
+ return true;
491
+ }
492
+ resolved = localPath;
493
+ }
494
+ const full = toBrowserNavigationHref(resolved, window.location.href, __basePath);
495
+ if (isHashOnlyChange(resolved)) {
496
+ const eventUrl = resolveHashUrl(resolved);
497
+ routerEvents.emit("hashChangeStart", eventUrl, { shallow: options?.shallow ?? false });
498
+ const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
499
+ window.history.pushState({}, "", resolved.startsWith("#") ? resolved : full);
500
+ _lastPathnameAndSearch = window.location.pathname + window.location.search;
501
+ scrollToHash(hash);
502
+ routerEvents.emit("hashChangeComplete", eventUrl, { shallow: options?.shallow ?? false });
503
+ window.dispatchEvent(new CustomEvent("vinext:navigate"));
504
+ return true;
505
+ }
506
+ saveScrollPosition();
507
+ routerEvents.emit("routeChangeStart", resolved, { shallow: options?.shallow ?? false });
508
+ routerEvents.emit("beforeHistoryChange", resolved, { shallow: options?.shallow ?? false });
509
+ window.history.pushState({}, "", full);
510
+ _lastPathnameAndSearch = window.location.pathname + window.location.search;
511
+ if (!options?.shallow) await navigateClient(full);
512
+ routerEvents.emit("routeChangeComplete", resolved, { shallow: options?.shallow ?? false });
513
+ const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
514
+ if (hash) scrollToHash(hash);
515
+ else if (options?.scroll !== false) window.scrollTo(0, 0);
516
+ window.dispatchEvent(new CustomEvent("vinext:navigate"));
517
+ return true;
518
+ },
519
+ replace: async (url, as, options) => {
520
+ let resolved = resolveNavigationTarget(url, as, options?.locale);
521
+ if (isExternalUrl(resolved)) {
522
+ const localPath = toSameOriginAppPath(resolved, __basePath);
523
+ if (localPath == null) {
524
+ window.location.replace(resolved);
525
+ return true;
526
+ }
527
+ resolved = localPath;
528
+ }
529
+ const full = toBrowserNavigationHref(resolved, window.location.href, __basePath);
530
+ if (isHashOnlyChange(resolved)) {
531
+ const eventUrl = resolveHashUrl(resolved);
532
+ routerEvents.emit("hashChangeStart", eventUrl, { shallow: options?.shallow ?? false });
533
+ const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
534
+ window.history.replaceState({}, "", resolved.startsWith("#") ? resolved : full);
535
+ _lastPathnameAndSearch = window.location.pathname + window.location.search;
536
+ scrollToHash(hash);
537
+ routerEvents.emit("hashChangeComplete", eventUrl, { shallow: options?.shallow ?? false });
538
+ window.dispatchEvent(new CustomEvent("vinext:navigate"));
539
+ return true;
540
+ }
541
+ routerEvents.emit("routeChangeStart", resolved, { shallow: options?.shallow ?? false });
542
+ routerEvents.emit("beforeHistoryChange", resolved, { shallow: options?.shallow ?? false });
543
+ window.history.replaceState({}, "", full);
544
+ _lastPathnameAndSearch = window.location.pathname + window.location.search;
545
+ if (!options?.shallow) await navigateClient(full);
546
+ routerEvents.emit("routeChangeComplete", resolved, { shallow: options?.shallow ?? false });
547
+ const hash = resolved.includes("#") ? resolved.slice(resolved.indexOf("#")) : "";
548
+ if (hash) scrollToHash(hash);
549
+ else if (options?.scroll !== false) window.scrollTo(0, 0);
550
+ window.dispatchEvent(new CustomEvent("vinext:navigate"));
551
+ return true;
552
+ },
553
+ back: () => window.history.back(),
554
+ reload: () => window.location.reload(),
555
+ prefetch: async (url) => {
556
+ if (typeof document !== "undefined") {
557
+ const link = document.createElement("link");
558
+ link.rel = "prefetch";
559
+ link.href = url;
560
+ link.as = "document";
561
+ document.head.appendChild(link);
562
+ }
563
+ },
564
+ beforePopState: (cb) => {
565
+ _beforePopStateCb = cb;
566
+ },
567
+ events: routerEvents
692
568
  };
693
- export default Router;
569
+ //#endregion
570
+ export { _registerRouterStateAccessors, applyNavigationLocale, Router as default, isExternalUrl, isHashOnlyChange, setSSRContext, useRouter, wrapWithRouterContext };
571
+
694
572
  //# sourceMappingURL=router.js.map