vinext 0.0.29 → 0.0.31

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