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.
- package/README.md +15 -7
- package/dist/build/prerender.d.ts +188 -0
- package/dist/build/prerender.js +675 -0
- package/dist/build/prerender.js.map +1 -0
- package/dist/build/report.d.ts +45 -46
- package/dist/build/report.js +581 -276
- package/dist/build/report.js.map +1 -1
- package/dist/build/run-prerender.d.ts +62 -0
- package/dist/build/run-prerender.js +183 -0
- package/dist/build/run-prerender.js.map +1 -0
- package/dist/build/server-manifest.d.ts +19 -0
- package/dist/build/server-manifest.js +29 -0
- package/dist/build/server-manifest.js.map +1 -0
- package/dist/build/static-export.d.ts +51 -66
- package/dist/build/static-export.js +51 -545
- package/dist/build/static-export.js.map +1 -1
- package/dist/check.d.ts +26 -24
- package/dist/check.js +681 -571
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +1 -15
- package/dist/cli.js +432 -491
- package/dist/cli.js.map +1 -1
- package/dist/client/entry.d.ts +1 -2
- package/dist/client/entry.js +49 -62
- package/dist/client/entry.js.map +1 -1
- package/dist/client/validate-module-path.d.ts +4 -1
- package/dist/client/validate-module-path.js +23 -28
- package/dist/client/validate-module-path.js.map +1 -1
- package/dist/client/vinext-next-data.d.ts +15 -20
- package/dist/client/vinext-next-data.js +0 -1
- package/dist/cloudflare/index.d.ts +3 -8
- package/dist/cloudflare/index.js +3 -8
- package/dist/cloudflare/kv-cache-handler.d.ts +95 -105
- package/dist/cloudflare/kv-cache-handler.js +354 -380
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/cloudflare/tpr.d.ts +36 -34
- package/dist/cloudflare/tpr.js +460 -603
- package/dist/cloudflare/tpr.js.map +1 -1
- package/dist/config/config-matchers.d.ts +31 -40
- package/dist/config/config-matchers.js +727 -936
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/dotenv.d.ts +18 -11
- package/dist/config/dotenv.js +79 -84
- package/dist/config/dotenv.js.map +1 -1
- package/dist/config/next-config.d.ts +156 -146
- package/dist/config/next-config.js +376 -464
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.d.ts +87 -96
- package/dist/deploy.js +490 -628
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-browser-entry.d.ts +4 -1
- package/dist/entries/app-browser-entry.js +12 -8
- package/dist/entries/app-browser-entry.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +33 -20
- package/dist/entries/app-rsc-entry.js +444 -212
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-ssr-entry.d.ts +9 -1
- package/dist/entries/app-ssr-entry.js +61 -28
- package/dist/entries/app-ssr-entry.js.map +1 -1
- package/dist/entries/pages-client-entry.d.ts +6 -2
- package/dist/entries/pages-client-entry.js +30 -33
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-entry-helpers.d.ts +5 -1
- package/dist/entries/pages-entry-helpers.js +17 -14
- package/dist/entries/pages-entry-helpers.js.map +1 -1
- package/dist/entries/pages-server-entry.d.ts +6 -2
- package/dist/entries/pages-server-entry.js +86 -114
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/index.d.ts +92 -60
- package/dist/index.js +2151 -3133
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +40 -37
- package/dist/init.js +201 -258
- package/dist/init.js.map +1 -1
- package/dist/plugins/async-hooks-stub.d.ts +7 -3
- package/dist/plugins/async-hooks-stub.js +39 -42
- package/dist/plugins/async-hooks-stub.js.map +1 -1
- package/dist/plugins/client-reference-dedup.d.ts +7 -3
- package/dist/plugins/client-reference-dedup.js +63 -88
- package/dist/plugins/client-reference-dedup.js.map +1 -1
- package/dist/routing/app-router.d.ts +100 -96
- package/dist/routing/app-router.js +560 -670
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/file-matcher.d.ts +18 -15
- package/dist/routing/file-matcher.js +65 -65
- package/dist/routing/file-matcher.js.map +1 -1
- package/dist/routing/pages-router.d.ts +23 -24
- package/dist/routing/pages-router.js +147 -172
- package/dist/routing/pages-router.js.map +1 -1
- package/dist/routing/route-trie.d.ts +23 -20
- package/dist/routing/route-trie.js +131 -151
- package/dist/routing/route-trie.js.map +1 -1
- package/dist/routing/route-validation.d.ts +5 -2
- package/dist/routing/route-validation.js +98 -130
- package/dist/routing/route-validation.js.map +1 -1
- package/dist/routing/utils.d.ts +10 -7
- package/dist/routing/utils.js +75 -111
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/api-handler.d.ts +8 -13
- package/dist/server/api-handler.js +160 -193
- package/dist/server/api-handler.js.map +1 -1
- package/dist/server/app-router-entry.d.ts +6 -16
- package/dist/server/app-router-entry.js +26 -54
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/dev-module-runner.d.ts +11 -64
- package/dist/server/dev-module-runner.js +89 -101
- package/dist/server/dev-module-runner.js.map +1 -1
- package/dist/server/dev-origin-check.d.ts +12 -10
- package/dist/server/dev-origin-check.js +98 -108
- package/dist/server/dev-origin-check.js.map +1 -1
- package/dist/server/dev-server.d.ts +19 -15
- package/dist/server/dev-server.js +543 -871
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/html.d.ts +4 -1
- package/dist/server/html.js +25 -26
- package/dist/server/html.js.map +1 -1
- package/dist/server/image-optimization.d.ts +31 -28
- package/dist/server/image-optimization.js +181 -210
- package/dist/server/image-optimization.js.map +1 -1
- package/dist/server/instrumentation.d.ts +34 -59
- package/dist/server/instrumentation.js +112 -125
- package/dist/server/instrumentation.js.map +1 -1
- package/dist/server/isr-cache.d.ts +16 -26
- package/dist/server/isr-cache.js +106 -128
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/metadata-routes.d.ts +85 -88
- package/dist/server/metadata-routes.js +270 -317
- package/dist/server/metadata-routes.js.map +1 -1
- package/dist/server/middleware-codegen.d.ts +7 -4
- package/dist/server/middleware-codegen.js +61 -61
- package/dist/server/middleware-codegen.js.map +1 -1
- package/dist/server/middleware-request-headers.d.ts +8 -6
- package/dist/server/middleware-request-headers.js +47 -65
- package/dist/server/middleware-request-headers.js.map +1 -1
- package/dist/server/middleware.d.ts +32 -47
- package/dist/server/middleware.js +261 -409
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/normalize-path.d.ts +4 -1
- package/dist/server/normalize-path.js +33 -47
- package/dist/server/normalize-path.js.map +1 -1
- package/dist/server/pages-i18n.d.ts +38 -30
- package/dist/server/pages-i18n.js +112 -139
- package/dist/server/pages-i18n.js.map +1 -1
- package/dist/server/prod-server.d.ts +19 -31
- package/dist/server/prod-server.js +715 -945
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/request-log.d.ts +18 -12
- package/dist/server/request-log.js +45 -52
- package/dist/server/request-log.js.map +1 -1
- package/dist/server/request-pipeline.d.ts +9 -17
- package/dist/server/request-pipeline.js +133 -184
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/worker-utils.d.ts +4 -1
- package/dist/server/worker-utils.js +31 -37
- package/dist/server/worker-utils.js.map +1 -1
- package/dist/shims/amp.d.ts +5 -2
- package/dist/shims/amp.js +19 -15
- package/dist/shims/amp.js.map +1 -1
- package/dist/shims/app.d.ts +8 -10
- package/dist/shims/app.js +0 -1
- package/dist/shims/cache-runtime.d.ts +20 -45
- package/dist/shims/cache-runtime.js +271 -422
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.d.ts +130 -121
- package/dist/shims/cache.js +339 -427
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/client-only.d.ts +1 -18
- package/dist/shims/client-only.js +0 -17
- package/dist/shims/compat-router.d.ts +6 -1
- package/dist/shims/compat-router.js +23 -19
- package/dist/shims/compat-router.js.map +1 -1
- package/dist/shims/config.d.ts +7 -5
- package/dist/shims/config.js +16 -23
- package/dist/shims/config.js.map +1 -1
- package/dist/shims/constants.d.ts +119 -118
- package/dist/shims/constants.js +159 -164
- package/dist/shims/constants.js.map +1 -1
- package/dist/shims/document.d.ts +20 -16
- package/dist/shims/document.js +41 -22
- package/dist/shims/document.js.map +1 -1
- package/dist/shims/dynamic.d.ts +13 -22
- package/dist/shims/dynamic.js +122 -136
- package/dist/shims/dynamic.js.map +1 -1
- package/dist/shims/error-boundary.d.ts +22 -15
- package/dist/shims/error-boundary.js +81 -79
- package/dist/shims/error-boundary.js.map +1 -1
- package/dist/shims/error.d.ts +11 -12
- package/dist/shims/error.js +35 -39
- package/dist/shims/error.js.map +1 -1
- package/dist/shims/fetch-cache.d.ts +16 -14
- package/dist/shims/fetch-cache.js +439 -645
- package/dist/shims/fetch-cache.js.map +1 -1
- package/dist/shims/font-google-base.d.ts +28 -26
- package/dist/shims/font-google-base.js +238 -325
- package/dist/shims/font-google-base.js.map +1 -1
- package/dist/shims/font-google.d.ts +3 -3
- package/dist/shims/font-google.generated.d.ts +1928 -1924
- package/dist/shims/font-google.generated.js +1928 -2133
- package/dist/shims/font-google.generated.js.map +1 -1
- package/dist/shims/font-google.js +3 -3
- package/dist/shims/font-local.d.ts +28 -26
- package/dist/shims/font-local.js +204 -260
- package/dist/shims/font-local.js.map +1 -1
- package/dist/shims/form.d.ts +13 -27
- package/dist/shims/form.js +128 -180
- package/dist/shims/form.js.map +1 -1
- package/dist/shims/head-state.d.ts +8 -13
- package/dist/shims/head-state.js +25 -42
- package/dist/shims/head-state.js.map +1 -1
- package/dist/shims/head.d.ts +17 -20
- package/dist/shims/head.js +194 -250
- package/dist/shims/head.js.map +1 -1
- package/dist/shims/headers.d.ts +84 -78
- package/dist/shims/headers.js +447 -575
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/i18n-context.d.ts +16 -20
- package/dist/shims/i18n-context.js +35 -48
- package/dist/shims/i18n-context.js.map +1 -1
- package/dist/shims/i18n-state.d.ts +8 -14
- package/dist/shims/i18n-state.js +34 -42
- package/dist/shims/i18n-state.js.map +1 -1
- package/dist/shims/image-config.d.ts +11 -8
- package/dist/shims/image-config.js +50 -83
- package/dist/shims/image-config.js.map +1 -1
- package/dist/shims/image.d.ts +37 -46
- package/dist/shims/image.js +283 -308
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/api-utils.d.ts +7 -4
- package/dist/shims/internal/api-utils.js +0 -6
- package/dist/shims/internal/app-router-context.d.ts +22 -17
- package/dist/shims/internal/app-router-context.js +17 -13
- package/dist/shims/internal/app-router-context.js.map +1 -1
- package/dist/shims/internal/cookies.d.ts +2 -9
- package/dist/shims/internal/cookies.js +2 -9
- package/dist/shims/internal/parse-cookie-header.d.ts +4 -1
- package/dist/shims/internal/parse-cookie-header.js +29 -29
- package/dist/shims/internal/parse-cookie-header.js.map +1 -1
- package/dist/shims/internal/router-context.d.ts +7 -1
- package/dist/shims/internal/router-context.js +11 -7
- package/dist/shims/internal/router-context.js.map +1 -1
- package/dist/shims/internal/utils.d.ts +40 -37
- package/dist/shims/internal/utils.js +24 -30
- package/dist/shims/internal/utils.js.map +1 -1
- package/dist/shims/internal/work-unit-async-storage.d.ts +6 -10
- package/dist/shims/internal/work-unit-async-storage.js +14 -11
- package/dist/shims/internal/work-unit-async-storage.js.map +1 -1
- package/dist/shims/layout-segment-context.d.ts +11 -14
- package/dist/shims/layout-segment-context.js +24 -23
- package/dist/shims/layout-segment-context.js.map +1 -1
- package/dist/shims/legacy-image.d.ts +39 -46
- package/dist/shims/legacy-image.js +47 -42
- package/dist/shims/legacy-image.js.map +1 -1
- package/dist/shims/link.d.ts +32 -36
- package/dist/shims/link.js +255 -391
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +210 -202
- package/dist/shims/metadata.js +545 -546
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation-state.d.ts +10 -18
- package/dist/shims/navigation-state.js +66 -74
- package/dist/shims/navigation-state.js.map +1 -1
- package/dist/shims/navigation.d.ts +59 -63
- package/dist/shims/navigation.js +505 -704
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/og.d.ts +2 -20
- package/dist/shims/og.js +2 -19
- package/dist/shims/readonly-url-search-params.d.ts +8 -5
- package/dist/shims/readonly-url-search-params.js +26 -22
- package/dist/shims/readonly-url-search-params.js.map +1 -1
- package/dist/shims/request-context.d.ts +8 -5
- package/dist/shims/request-context.js +50 -60
- package/dist/shims/request-context.js.map +1 -1
- package/dist/shims/request-state-types.d.ts +11 -11
- package/dist/shims/request-state-types.js +0 -1
- package/dist/shims/router-state.d.ts +13 -10
- package/dist/shims/router-state.js +34 -43
- package/dist/shims/router-state.js.map +1 -1
- package/dist/shims/router.d.ts +81 -85
- package/dist/shims/router.js +506 -628
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/script.d.ts +39 -48
- package/dist/shims/script.js +107 -160
- package/dist/shims/script.js.map +1 -1
- package/dist/shims/server-only.d.ts +1 -19
- package/dist/shims/server-only.js +0 -18
- package/dist/shims/server.d.ts +213 -164
- package/dist/shims/server.js +545 -478
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/unified-request-context.d.ts +20 -20
- package/dist/shims/unified-request-context.js +81 -99
- package/dist/shims/unified-request-context.js.map +1 -1
- package/dist/shims/url-safety.d.ts +4 -1
- package/dist/shims/url-safety.js +15 -11
- package/dist/shims/url-safety.js.map +1 -1
- package/dist/shims/url-utils.d.ts +8 -5
- package/dist/shims/url-utils.js +62 -93
- package/dist/shims/url-utils.js.map +1 -1
- package/dist/shims/web-vitals.d.ts +10 -8
- package/dist/shims/web-vitals.js +9 -15
- package/dist/shims/web-vitals.js.map +1 -1
- package/dist/utils/base-path.d.ts +5 -2
- package/dist/utils/base-path.js +21 -19
- package/dist/utils/base-path.js.map +1 -1
- package/dist/utils/domain-locale.d.ts +17 -9
- package/dist/utils/domain-locale.js +36 -56
- package/dist/utils/domain-locale.js.map +1 -1
- package/dist/utils/hash.d.ts +4 -1
- package/dist/utils/hash.js +19 -17
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/manifest-paths.d.ts +6 -3
- package/dist/utils/manifest-paths.js +15 -16
- package/dist/utils/manifest-paths.js.map +1 -1
- package/dist/utils/project.d.ts +13 -11
- package/dist/utils/project.js +169 -216
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/query.d.ts +8 -6
- package/dist/utils/query.js +57 -67
- package/dist/utils/query.js.map +1 -1
- package/package.json +10 -9
- package/dist/build/report.d.ts.map +0 -1
- package/dist/build/static-export.d.ts.map +0 -1
- package/dist/check.d.ts.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/client/entry.d.ts.map +0 -1
- package/dist/client/validate-module-path.d.ts.map +0 -1
- package/dist/client/vinext-next-data.d.ts.map +0 -1
- package/dist/client/vinext-next-data.js.map +0 -1
- package/dist/cloudflare/index.d.ts.map +0 -1
- package/dist/cloudflare/index.js.map +0 -1
- package/dist/cloudflare/kv-cache-handler.d.ts.map +0 -1
- package/dist/cloudflare/tpr.d.ts.map +0 -1
- package/dist/config/config-matchers.d.ts.map +0 -1
- package/dist/config/dotenv.d.ts.map +0 -1
- package/dist/config/next-config.d.ts.map +0 -1
- package/dist/deploy.d.ts.map +0 -1
- package/dist/entries/app-browser-entry.d.ts.map +0 -1
- package/dist/entries/app-rsc-entry.d.ts.map +0 -1
- package/dist/entries/app-ssr-entry.d.ts.map +0 -1
- package/dist/entries/pages-client-entry.d.ts.map +0 -1
- package/dist/entries/pages-entry-helpers.d.ts.map +0 -1
- package/dist/entries/pages-server-entry.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/init.d.ts.map +0 -1
- package/dist/plugins/async-hooks-stub.d.ts.map +0 -1
- package/dist/plugins/client-reference-dedup.d.ts.map +0 -1
- package/dist/routing/app-router.d.ts.map +0 -1
- package/dist/routing/file-matcher.d.ts.map +0 -1
- package/dist/routing/pages-router.d.ts.map +0 -1
- package/dist/routing/route-trie.d.ts.map +0 -1
- package/dist/routing/route-validation.d.ts.map +0 -1
- package/dist/routing/utils.d.ts.map +0 -1
- package/dist/server/api-handler.d.ts.map +0 -1
- package/dist/server/app-router-entry.d.ts.map +0 -1
- package/dist/server/dev-module-runner.d.ts.map +0 -1
- package/dist/server/dev-origin-check.d.ts.map +0 -1
- package/dist/server/dev-server.d.ts.map +0 -1
- package/dist/server/html.d.ts.map +0 -1
- package/dist/server/image-optimization.d.ts.map +0 -1
- package/dist/server/instrumentation.d.ts.map +0 -1
- package/dist/server/isr-cache.d.ts.map +0 -1
- package/dist/server/metadata-routes.d.ts.map +0 -1
- package/dist/server/middleware-codegen.d.ts.map +0 -1
- package/dist/server/middleware-request-headers.d.ts.map +0 -1
- package/dist/server/middleware.d.ts.map +0 -1
- package/dist/server/normalize-path.d.ts.map +0 -1
- package/dist/server/pages-i18n.d.ts.map +0 -1
- package/dist/server/prod-server.d.ts.map +0 -1
- package/dist/server/request-log.d.ts.map +0 -1
- package/dist/server/request-pipeline.d.ts.map +0 -1
- package/dist/server/worker-utils.d.ts.map +0 -1
- package/dist/shims/amp.d.ts.map +0 -1
- package/dist/shims/app.d.ts.map +0 -1
- package/dist/shims/app.js.map +0 -1
- package/dist/shims/cache-runtime.d.ts.map +0 -1
- package/dist/shims/cache.d.ts.map +0 -1
- package/dist/shims/client-only.d.ts.map +0 -1
- package/dist/shims/client-only.js.map +0 -1
- package/dist/shims/compat-router.d.ts.map +0 -1
- package/dist/shims/config.d.ts.map +0 -1
- package/dist/shims/constants.d.ts.map +0 -1
- package/dist/shims/document.d.ts.map +0 -1
- package/dist/shims/dynamic.d.ts.map +0 -1
- package/dist/shims/error-boundary.d.ts.map +0 -1
- package/dist/shims/error.d.ts.map +0 -1
- package/dist/shims/fetch-cache.d.ts.map +0 -1
- package/dist/shims/font-google-base.d.ts.map +0 -1
- package/dist/shims/font-google.d.ts.map +0 -1
- package/dist/shims/font-google.generated.d.ts.map +0 -1
- package/dist/shims/font-google.js.map +0 -1
- package/dist/shims/font-local.d.ts.map +0 -1
- package/dist/shims/form.d.ts.map +0 -1
- package/dist/shims/head-state.d.ts.map +0 -1
- package/dist/shims/head.d.ts.map +0 -1
- package/dist/shims/headers.d.ts.map +0 -1
- package/dist/shims/i18n-context.d.ts.map +0 -1
- package/dist/shims/i18n-state.d.ts.map +0 -1
- package/dist/shims/image-config.d.ts.map +0 -1
- package/dist/shims/image.d.ts.map +0 -1
- package/dist/shims/internal/api-utils.d.ts.map +0 -1
- package/dist/shims/internal/api-utils.js.map +0 -1
- package/dist/shims/internal/app-router-context.d.ts.map +0 -1
- package/dist/shims/internal/cookies.d.ts.map +0 -1
- package/dist/shims/internal/cookies.js.map +0 -1
- package/dist/shims/internal/parse-cookie-header.d.ts.map +0 -1
- package/dist/shims/internal/router-context.d.ts.map +0 -1
- package/dist/shims/internal/utils.d.ts.map +0 -1
- package/dist/shims/internal/work-unit-async-storage.d.ts.map +0 -1
- package/dist/shims/layout-segment-context.d.ts.map +0 -1
- package/dist/shims/legacy-image.d.ts.map +0 -1
- package/dist/shims/link.d.ts.map +0 -1
- package/dist/shims/metadata.d.ts.map +0 -1
- package/dist/shims/navigation-state.d.ts.map +0 -1
- package/dist/shims/navigation.d.ts.map +0 -1
- package/dist/shims/og.d.ts.map +0 -1
- package/dist/shims/og.js.map +0 -1
- package/dist/shims/readonly-url-search-params.d.ts.map +0 -1
- package/dist/shims/request-context.d.ts.map +0 -1
- package/dist/shims/request-state-types.d.ts.map +0 -1
- package/dist/shims/request-state-types.js.map +0 -1
- package/dist/shims/router-state.d.ts.map +0 -1
- package/dist/shims/router.d.ts.map +0 -1
- package/dist/shims/script.d.ts.map +0 -1
- package/dist/shims/server-only.d.ts.map +0 -1
- package/dist/shims/server-only.js.map +0 -1
- package/dist/shims/server.d.ts.map +0 -1
- package/dist/shims/unified-request-context.d.ts.map +0 -1
- package/dist/shims/url-safety.d.ts.map +0 -1
- package/dist/shims/url-utils.d.ts.map +0 -1
- package/dist/shims/web-vitals.d.ts.map +0 -1
- package/dist/utils/base-path.d.ts.map +0 -1
- package/dist/utils/domain-locale.d.ts.map +0 -1
- package/dist/utils/hash.d.ts.map +0 -1
- package/dist/utils/manifest-paths.d.ts.map +0 -1
- package/dist/utils/project.d.ts.map +0 -1
- package/dist/utils/query.d.ts.map +0 -1
package/dist/shims/router.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
51
|
+
return applyNavigationLocale(as ?? resolveUrl(url), locale);
|
|
54
52
|
}
|
|
55
53
|
function getDomainLocales() {
|
|
56
|
-
|
|
54
|
+
return window.__NEXT_DATA__?.domainLocales;
|
|
57
55
|
}
|
|
58
56
|
function getCurrentHostname() {
|
|
59
|
-
|
|
57
|
+
return window.location?.hostname;
|
|
60
58
|
}
|
|
61
59
|
function getDomainLocalePath(url, locale) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
return getDomainLocaleUrl(url, locale, {
|
|
61
|
+
basePath: __basePath,
|
|
62
|
+
currentHostname: getCurrentHostname(),
|
|
63
|
+
domainItems: getDomainLocales()
|
|
64
|
+
});
|
|
67
65
|
}
|
|
68
66
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
87
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
132
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
132
|
+
_ssrContext = ctx;
|
|
150
133
|
};
|
|
151
134
|
/**
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
160
|
-
|
|
142
|
+
function setSSRContext(ctx) {
|
|
143
|
+
_setSSRContextImpl(ctx);
|
|
161
144
|
}
|
|
162
145
|
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
230
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
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
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
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
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
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
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
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
|
-
|
|
569
|
+
//#endregion
|
|
570
|
+
export { _registerRouterStateAccessors, applyNavigationLocale, Router as default, isExternalUrl, isHashOnlyChange, setSSRContext, useRouter, wrapWithRouterContext };
|
|
571
|
+
|
|
694
572
|
//# sourceMappingURL=router.js.map
|