react-router 7.15.1 → 8.0.0-pre.0
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/CHANGELOG.md +18 -2
- package/dist/development/dom-export.d.ts +6 -172
- package/dist/development/dom-export.js +12 -1007
- package/dist/development/index-react-server-client.d.ts +7 -4
- package/dist/development/index-react-server-client.js +8 -52
- package/dist/development/index-react-server.d.ts +1645 -1635
- package/dist/development/index-react-server.js +2880 -3642
- package/dist/development/index.d.ts +43 -1469
- package/dist/development/index.js +37 -2621
- package/dist/development/lib/actions.js +62 -0
- package/dist/development/lib/components.d.ts +1022 -0
- package/dist/development/lib/components.js +835 -0
- package/dist/development/lib/context.d.ts +83 -0
- package/dist/development/lib/context.js +41 -0
- package/dist/development/lib/dom/dom.d.ts +119 -0
- package/dist/development/lib/dom/dom.js +143 -0
- package/dist/development/lib/dom/lib.d.ts +2042 -0
- package/dist/development/lib/dom/lib.js +1259 -0
- package/dist/development/lib/dom/server.d.ts +138 -0
- package/dist/development/lib/dom/server.js +301 -0
- package/dist/development/lib/dom/ssr/components.d.ts +196 -0
- package/dist/development/lib/dom/ssr/components.js +579 -0
- package/dist/development/lib/dom/ssr/data.js +29 -0
- package/dist/development/lib/dom/ssr/entry.d.ts +59 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.js +83 -0
- package/dist/development/lib/dom/ssr/errors.d.ts +7 -0
- package/dist/development/lib/dom/ssr/errors.js +36 -0
- package/dist/development/lib/dom/ssr/fallback.js +28 -0
- package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/development/lib/dom/ssr/fog-of-war.js +170 -0
- package/dist/development/lib/dom/ssr/hydration.d.ts +32 -0
- package/dist/development/lib/dom/ssr/hydration.js +29 -0
- package/dist/development/lib/dom/ssr/invariant.js +16 -0
- package/dist/development/lib/dom/ssr/links.js +170 -0
- package/dist/development/lib/dom/ssr/markup.js +24 -0
- package/dist/development/lib/dom/ssr/routeModules.d.ts +206 -0
- package/dist/development/lib/dom/ssr/routeModules.js +31 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.d.ts +62 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.js +108 -0
- package/dist/development/lib/dom/ssr/routes.d.ts +33 -0
- package/dist/development/lib/dom/ssr/routes.js +303 -0
- package/dist/development/lib/dom/ssr/server.d.ts +45 -0
- package/dist/development/lib/dom/ssr/server.js +68 -0
- package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/development/lib/dom/ssr/single-fetch.js +346 -0
- package/dist/development/lib/dom-export/dom-router-provider.d.ts +9 -0
- package/dist/development/lib/dom-export/dom-router-provider.js +22 -0
- package/dist/development/lib/dom-export/hydrated-router.d.ts +125 -0
- package/dist/development/lib/dom-export/hydrated-router.js +153 -0
- package/dist/development/lib/errors.js +29 -0
- package/dist/development/lib/hooks.d.ts +947 -0
- package/dist/development/lib/hooks.js +1386 -0
- package/dist/development/lib/href.d.ts +20 -0
- package/dist/development/lib/href.js +50 -0
- package/dist/development/lib/router/history.d.ts +258 -0
- package/dist/development/lib/router/history.js +371 -0
- package/dist/development/lib/router/instrumentation.d.ts +86 -0
- package/dist/development/lib/router/instrumentation.js +213 -0
- package/dist/development/lib/router/links.d.ts +113 -0
- package/dist/development/lib/router/router.d.ts +663 -0
- package/dist/development/lib/router/router.js +2981 -0
- package/dist/development/lib/router/utils.d.ts +942 -0
- package/dist/development/lib/router/utils.js +791 -0
- package/dist/development/lib/rsc/browser.d.ts +137 -0
- package/dist/development/lib/rsc/browser.js +599 -0
- package/dist/development/lib/rsc/errorBoundaries.d.ts +11 -0
- package/dist/development/lib/rsc/errorBoundaries.js +90 -0
- package/dist/development/lib/rsc/html-stream/browser.d.ts +48 -0
- package/dist/development/lib/rsc/html-stream/browser.js +74 -0
- package/dist/development/lib/rsc/html-stream/server.js +78 -0
- package/dist/development/lib/rsc/route-modules.js +27 -0
- package/dist/development/lib/rsc/server.rsc.d.ts +219 -0
- package/dist/development/lib/rsc/server.ssr.d.ts +129 -0
- package/dist/development/lib/rsc/server.ssr.js +388 -0
- package/dist/development/lib/server-runtime/build.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.js +139 -0
- package/dist/development/lib/server-runtime/crypto.js +43 -0
- package/dist/development/lib/server-runtime/data.d.ts +13 -0
- package/dist/development/lib/server-runtime/data.js +25 -0
- package/dist/development/lib/server-runtime/dev.d.ts +9 -0
- package/dist/development/lib/server-runtime/dev.js +26 -0
- package/dist/development/lib/server-runtime/entry.js +20 -0
- package/dist/development/lib/server-runtime/errors.js +95 -0
- package/dist/development/lib/server-runtime/headers.js +73 -0
- package/dist/development/lib/server-runtime/invariant.js +19 -0
- package/dist/development/lib/server-runtime/mode.d.ts +12 -0
- package/dist/development/lib/server-runtime/mode.js +25 -0
- package/dist/development/lib/server-runtime/routeMatching.js +28 -0
- package/dist/development/lib/server-runtime/routes.d.ts +13 -0
- package/dist/development/lib/server-runtime/routes.js +74 -0
- package/dist/development/lib/server-runtime/server.d.ts +10 -0
- package/dist/development/lib/server-runtime/server.js +351 -0
- package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +45 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +52 -0
- package/dist/development/lib/server-runtime/sessions.d.ts +145 -0
- package/dist/development/lib/server-runtime/sessions.js +98 -0
- package/dist/development/lib/server-runtime/single-fetch.d.ts +7 -0
- package/dist/development/lib/server-runtime/single-fetch.js +215 -0
- package/dist/development/lib/server-runtime/urls.js +31 -0
- package/dist/development/lib/server-runtime/warnings.js +20 -0
- package/dist/development/lib/types/future.d.ts +9 -0
- package/dist/development/lib/types/internal.d.ts +26 -177
- package/dist/development/lib/types/internal.js +3 -2
- package/dist/{production/register-Bsscfj79.d.ts → development/lib/types/register.d.ts} +9 -15
- package/dist/development/lib/types/route-data.d.ts +113 -0
- package/dist/development/lib/types/route-module-annotations.d.ts +149 -0
- package/dist/development/lib/types/route-module.d.ts +19 -0
- package/dist/development/lib/types/serializes-to.d.ts +13 -0
- package/dist/development/lib/types/utils.d.ts +11 -0
- package/dist/development/vendor/turbo-stream-v2/flatten.js +159 -0
- package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +178 -0
- package/dist/development/vendor/turbo-stream-v2/unflatten.js +198 -0
- package/dist/development/vendor/turbo-stream-v2/utils.js +47 -0
- package/dist/production/dom-export.d.ts +6 -172
- package/dist/production/dom-export.js +12 -1007
- package/dist/production/index-react-server-client.d.ts +7 -4
- package/dist/production/index-react-server-client.js +8 -52
- package/dist/production/index-react-server.d.ts +1645 -1635
- package/dist/production/index-react-server.js +2871 -3642
- package/dist/production/index.d.ts +43 -1469
- package/dist/production/index.js +37 -2621
- package/dist/production/lib/actions.js +62 -0
- package/dist/production/lib/components.d.ts +1022 -0
- package/dist/production/lib/components.js +835 -0
- package/dist/production/lib/context.d.ts +83 -0
- package/dist/production/lib/context.js +41 -0
- package/dist/production/lib/dom/dom.d.ts +119 -0
- package/dist/production/lib/dom/dom.js +143 -0
- package/dist/production/lib/dom/lib.d.ts +2042 -0
- package/dist/production/lib/dom/lib.js +1259 -0
- package/dist/production/lib/dom/server.d.ts +138 -0
- package/dist/production/lib/dom/server.js +301 -0
- package/dist/production/lib/dom/ssr/components.d.ts +196 -0
- package/dist/production/lib/dom/ssr/components.js +579 -0
- package/dist/production/lib/dom/ssr/data.js +29 -0
- package/dist/production/lib/dom/ssr/entry.d.ts +59 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.js +83 -0
- package/dist/production/lib/dom/ssr/errors.d.ts +7 -0
- package/dist/production/lib/dom/ssr/errors.js +36 -0
- package/dist/production/lib/dom/ssr/fallback.js +21 -0
- package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/production/lib/dom/ssr/fog-of-war.js +170 -0
- package/dist/production/lib/dom/ssr/hydration.d.ts +32 -0
- package/dist/production/lib/dom/ssr/hydration.js +29 -0
- package/dist/production/lib/dom/ssr/invariant.js +16 -0
- package/dist/production/lib/dom/ssr/links.js +170 -0
- package/dist/production/lib/dom/ssr/markup.js +24 -0
- package/dist/production/lib/dom/ssr/routeModules.d.ts +206 -0
- package/dist/production/lib/dom/ssr/routeModules.js +31 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.d.ts +62 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.js +108 -0
- package/dist/production/lib/dom/ssr/routes.d.ts +33 -0
- package/dist/production/lib/dom/ssr/routes.js +303 -0
- package/dist/production/lib/dom/ssr/server.d.ts +45 -0
- package/dist/production/lib/dom/ssr/server.js +68 -0
- package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/production/lib/dom/ssr/single-fetch.js +346 -0
- package/dist/production/lib/dom-export/dom-router-provider.d.ts +9 -0
- package/dist/production/lib/dom-export/dom-router-provider.js +22 -0
- package/dist/production/lib/dom-export/hydrated-router.d.ts +125 -0
- package/dist/production/lib/dom-export/hydrated-router.js +153 -0
- package/dist/production/lib/errors.js +29 -0
- package/dist/production/lib/hooks.d.ts +947 -0
- package/dist/production/lib/hooks.js +1371 -0
- package/dist/production/lib/href.d.ts +20 -0
- package/dist/production/lib/href.js +50 -0
- package/dist/production/lib/router/history.d.ts +258 -0
- package/dist/production/lib/router/history.js +371 -0
- package/dist/production/lib/router/instrumentation.d.ts +86 -0
- package/dist/production/lib/router/instrumentation.js +213 -0
- package/dist/production/lib/router/links.d.ts +113 -0
- package/dist/production/lib/router/router.d.ts +663 -0
- package/dist/production/lib/router/router.js +2981 -0
- package/dist/production/lib/router/utils.d.ts +942 -0
- package/dist/production/lib/router/utils.js +782 -0
- package/dist/production/lib/rsc/browser.d.ts +137 -0
- package/dist/production/lib/rsc/browser.js +599 -0
- package/dist/production/lib/rsc/errorBoundaries.d.ts +11 -0
- package/dist/production/lib/rsc/errorBoundaries.js +90 -0
- package/dist/production/lib/rsc/html-stream/browser.d.ts +48 -0
- package/dist/production/lib/rsc/html-stream/browser.js +74 -0
- package/dist/production/lib/rsc/html-stream/server.js +78 -0
- package/dist/production/lib/rsc/route-modules.js +27 -0
- package/dist/production/lib/rsc/server.rsc.d.ts +219 -0
- package/dist/production/lib/rsc/server.ssr.d.ts +129 -0
- package/dist/production/lib/rsc/server.ssr.js +388 -0
- package/dist/production/lib/server-runtime/build.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.js +139 -0
- package/dist/production/lib/server-runtime/crypto.js +43 -0
- package/dist/production/lib/server-runtime/data.d.ts +13 -0
- package/dist/production/lib/server-runtime/data.js +25 -0
- package/dist/production/lib/server-runtime/dev.d.ts +9 -0
- package/dist/production/lib/server-runtime/dev.js +26 -0
- package/dist/production/lib/server-runtime/entry.js +20 -0
- package/dist/production/lib/server-runtime/errors.js +95 -0
- package/dist/production/lib/server-runtime/headers.js +73 -0
- package/dist/production/lib/server-runtime/invariant.js +19 -0
- package/dist/production/lib/server-runtime/mode.d.ts +12 -0
- package/dist/production/lib/server-runtime/mode.js +25 -0
- package/dist/production/lib/server-runtime/routeMatching.js +28 -0
- package/dist/production/lib/server-runtime/routes.d.ts +13 -0
- package/dist/production/lib/server-runtime/routes.js +74 -0
- package/dist/production/lib/server-runtime/server.d.ts +10 -0
- package/dist/production/lib/server-runtime/server.js +351 -0
- package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +45 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +52 -0
- package/dist/production/lib/server-runtime/sessions.d.ts +145 -0
- package/dist/production/lib/server-runtime/sessions.js +98 -0
- package/dist/production/lib/server-runtime/single-fetch.d.ts +7 -0
- package/dist/production/lib/server-runtime/single-fetch.js +215 -0
- package/dist/production/lib/server-runtime/urls.js +31 -0
- package/dist/production/lib/server-runtime/warnings.js +20 -0
- package/dist/production/lib/types/future.d.ts +9 -0
- package/dist/production/lib/types/internal.d.ts +26 -177
- package/dist/production/lib/types/internal.js +3 -2
- package/dist/{development/register-Bsscfj79.d.ts → production/lib/types/register.d.ts} +9 -15
- package/dist/production/lib/types/route-data.d.ts +113 -0
- package/dist/production/lib/types/route-module-annotations.d.ts +149 -0
- package/dist/production/lib/types/route-module.d.ts +19 -0
- package/dist/production/lib/types/serializes-to.d.ts +13 -0
- package/dist/production/lib/types/utils.d.ts +11 -0
- package/dist/production/vendor/turbo-stream-v2/flatten.js +159 -0
- package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +178 -0
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +198 -0
- package/dist/production/vendor/turbo-stream-v2/utils.js +47 -0
- package/docs/explanation/backend-for-frontend.md +50 -0
- package/docs/explanation/code-splitting.md +77 -0
- package/docs/explanation/concurrency.md +135 -0
- package/docs/explanation/form-vs-fetcher.md +292 -0
- package/docs/explanation/hot-module-replacement.md +137 -0
- package/docs/explanation/hydration.md +14 -0
- package/docs/explanation/index-query-param.md +86 -0
- package/docs/explanation/index.md +4 -0
- package/docs/explanation/lazy-route-discovery.md +78 -0
- package/docs/explanation/location.md +6 -0
- package/docs/explanation/progressive-enhancement.md +150 -0
- package/docs/explanation/race-conditions.md +88 -0
- package/docs/explanation/react-transitions.md +160 -0
- package/docs/explanation/route-matching.md +7 -0
- package/docs/explanation/server-client-execution.md +4 -0
- package/docs/explanation/sessions-and-cookies.md +465 -0
- package/docs/explanation/special-files.md +16 -0
- package/docs/explanation/state-management.md +524 -0
- package/docs/explanation/styling.md +87 -0
- package/docs/explanation/type-safety.md +82 -0
- package/docs/how-to/accessibility.md +44 -0
- package/docs/how-to/client-data.md +199 -0
- package/docs/how-to/data-strategy.md +317 -0
- package/docs/how-to/error-boundary.md +231 -0
- package/docs/how-to/error-reporting.md +134 -0
- package/docs/how-to/fetchers.md +307 -0
- package/docs/how-to/file-route-conventions.md +410 -0
- package/docs/how-to/file-uploads.md +217 -0
- package/docs/how-to/form-validation.md +120 -0
- package/docs/how-to/headers.md +164 -0
- package/docs/how-to/index.md +4 -0
- package/docs/how-to/instrumentation.md +556 -0
- package/docs/how-to/meta.md +40 -0
- package/docs/how-to/middleware.md +728 -0
- package/docs/how-to/navigation-blocking.md +233 -0
- package/docs/how-to/optimize-revalidation.md +12 -0
- package/docs/how-to/pre-rendering.md +225 -0
- package/docs/how-to/presets.md +103 -0
- package/docs/how-to/react-server-components.md +899 -0
- package/docs/how-to/resource-routes.md +126 -0
- package/docs/how-to/route-module-type-safety.md +100 -0
- package/docs/how-to/search-params.md +4 -0
- package/docs/how-to/security.md +30 -0
- package/docs/how-to/server-bundles.md +66 -0
- package/docs/how-to/spa.md +120 -0
- package/docs/how-to/status.md +63 -0
- package/docs/how-to/suspense.md +132 -0
- package/docs/how-to/using-handle.md +117 -0
- package/docs/how-to/view-transitions.md +237 -0
- package/docs/how-to/webhook.md +50 -0
- package/docs/index.md +39 -0
- package/docs/start/data/actions.md +138 -0
- package/docs/start/data/custom.md +198 -0
- package/docs/start/data/data-loading.md +44 -0
- package/docs/start/data/index.md +4 -0
- package/docs/start/data/installation.md +52 -0
- package/docs/start/data/navigating.md +12 -0
- package/docs/start/data/pending-ui.md +12 -0
- package/docs/start/data/route-object.md +248 -0
- package/docs/start/data/routing.md +281 -0
- package/docs/start/data/testing.md +8 -0
- package/docs/start/declarative/index.md +4 -0
- package/docs/start/declarative/installation.md +43 -0
- package/docs/start/declarative/navigating.md +133 -0
- package/docs/start/declarative/routing.md +237 -0
- package/docs/start/declarative/url-values.md +65 -0
- package/docs/start/framework/actions.md +175 -0
- package/docs/start/framework/data-loading.md +201 -0
- package/docs/start/framework/deploying.md +96 -0
- package/docs/start/framework/index.md +4 -0
- package/docs/start/framework/installation.md +42 -0
- package/docs/start/framework/navigating.md +182 -0
- package/docs/start/framework/pending-ui.md +142 -0
- package/docs/start/framework/rendering.md +59 -0
- package/docs/start/framework/route-module.md +527 -0
- package/docs/start/framework/routing.md +362 -0
- package/docs/start/framework/testing.md +133 -0
- package/docs/start/index.md +4 -0
- package/docs/start/modes.md +201 -0
- package/docs/upgrading/component-routes.md +363 -0
- package/docs/upgrading/future.md +31 -0
- package/docs/upgrading/index.md +4 -0
- package/docs/upgrading/remix.md +403 -0
- package/docs/upgrading/router-provider.md +442 -0
- package/docs/upgrading/v6.md +379 -0
- package/package.json +44 -87
- package/dist/development/browser-3AnU12UI.d.mts +0 -318
- package/dist/development/browser-BOdXz9dK.d.ts +0 -318
- package/dist/development/chunk-4N6VE7H7.mjs +0 -11528
- package/dist/development/chunk-4YRVXM2U.js +0 -188
- package/dist/development/chunk-66UKHEGQ.js +0 -1362
- package/dist/development/chunk-D6LUOGOQ.js +0 -10229
- package/dist/development/chunk-RJYABSBD.mjs +0 -2585
- package/dist/development/context-ByvtofY2.d.mts +0 -1771
- package/dist/development/data-BVUf681J.d.mts +0 -1732
- package/dist/development/data-BqZ2x964.d.ts +0 -1732
- package/dist/development/dom-export.d.mts +0 -172
- package/dist/development/dom-export.mjs +0 -1008
- package/dist/development/index-react-server-client-BS5F89FR.d.ts +0 -3655
- package/dist/development/index-react-server-client-DY04-103.d.mts +0 -2600
- package/dist/development/index-react-server-client.d.mts +0 -4
- package/dist/development/index-react-server-client.mjs +0 -59
- package/dist/development/index-react-server.d.mts +0 -2703
- package/dist/development/index-react-server.mjs +0 -3780
- package/dist/development/index.d.mts +0 -1472
- package/dist/development/index.mjs +0 -277
- package/dist/development/instrumentation-cRWWLfsU.d.ts +0 -715
- package/dist/development/lib/types/internal.d.mts +0 -184
- package/dist/development/lib/types/internal.mjs +0 -10
- package/dist/development/register-Df8okEea.d.mts +0 -30
- package/dist/production/browser-3AnU12UI.d.mts +0 -318
- package/dist/production/browser-BOdXz9dK.d.ts +0 -318
- package/dist/production/chunk-6S4627ZB.mjs +0 -2585
- package/dist/production/chunk-HUBUW7R3.js +0 -10229
- package/dist/production/chunk-JAKZPQZC.mjs +0 -11528
- package/dist/production/chunk-PNZCCTKT.js +0 -1362
- package/dist/production/chunk-Y6IFXO7V.js +0 -188
- package/dist/production/context-ByvtofY2.d.mts +0 -1771
- package/dist/production/data-BVUf681J.d.mts +0 -1732
- package/dist/production/data-BqZ2x964.d.ts +0 -1732
- package/dist/production/dom-export.d.mts +0 -172
- package/dist/production/dom-export.mjs +0 -1008
- package/dist/production/index-react-server-client-BS5F89FR.d.ts +0 -3655
- package/dist/production/index-react-server-client-DY04-103.d.mts +0 -2600
- package/dist/production/index-react-server-client.d.mts +0 -4
- package/dist/production/index-react-server-client.mjs +0 -59
- package/dist/production/index-react-server.d.mts +0 -2703
- package/dist/production/index-react-server.mjs +0 -3780
- package/dist/production/index.d.mts +0 -1472
- package/dist/production/index.mjs +0 -277
- package/dist/production/instrumentation-cRWWLfsU.d.ts +0 -715
- package/dist/production/lib/types/internal.d.mts +0 -184
- package/dist/production/lib/types/internal.mjs +0 -10
- package/dist/production/register-Df8okEea.d.mts +0 -30
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
import { Equal } from "./types/utils.js";
|
|
3
|
+
import { Pages } from "./types/register.js";
|
|
4
|
+
|
|
5
|
+
//#region lib/href.d.ts
|
|
6
|
+
type Args = { [K in keyof Pages]: ToArgs<Pages[K]["params"]> };
|
|
7
|
+
type ToArgs<Params extends Record<string, string | undefined>> = Equal<Params, {}> extends true ? [] : Partial<Params> extends Params ? [Params] | [] : [Params];
|
|
8
|
+
/**
|
|
9
|
+
Returns a resolved URL path for the specified route.
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
const h = href("/:lang?/about", { lang: "en" })
|
|
13
|
+
// -> `/en/about`
|
|
14
|
+
|
|
15
|
+
<Link to={href("/products/:id", { id: "abc123" })} />
|
|
16
|
+
```
|
|
17
|
+
*/
|
|
18
|
+
declare function href<Path extends keyof Args>(path: Path, ...args: Args[Path]): string;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { href };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-router v8.0.0-pre.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
//#region lib/href.ts
|
|
12
|
+
/**
|
|
13
|
+
Returns a resolved URL path for the specified route.
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
const h = href("/:lang?/about", { lang: "en" })
|
|
17
|
+
// -> `/en/about`
|
|
18
|
+
|
|
19
|
+
<Link to={href("/products/:id", { id: "abc123" })} />
|
|
20
|
+
```
|
|
21
|
+
*/
|
|
22
|
+
function href(path, ...args) {
|
|
23
|
+
let params = args[0];
|
|
24
|
+
let result = trimTrailingSplat(path).replace(/\/:([\w-]+)(\?)?/g, (_, param, questionMark) => {
|
|
25
|
+
const isRequired = questionMark === void 0;
|
|
26
|
+
const value = params?.[param];
|
|
27
|
+
if (isRequired && value === void 0) throw new Error(`Path '${path}' requires param '${param}' but it was not provided`);
|
|
28
|
+
return value === void 0 ? "" : "/" + value;
|
|
29
|
+
});
|
|
30
|
+
if (path.endsWith("*")) {
|
|
31
|
+
const value = params?.["*"];
|
|
32
|
+
if (value !== void 0) result += "/" + value;
|
|
33
|
+
}
|
|
34
|
+
return result || "/";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Removes a trailing splat and any number of slashes from the end of the path.
|
|
38
|
+
*
|
|
39
|
+
* Benchmarked to be faster than `path.replace(/\/*\*?$/, "")`, which backtracks.
|
|
40
|
+
*/
|
|
41
|
+
function trimTrailingSplat(path) {
|
|
42
|
+
let i = path.length - 1;
|
|
43
|
+
let char = path[i];
|
|
44
|
+
if (char !== "*" && char !== "/") return path;
|
|
45
|
+
i--;
|
|
46
|
+
for (; i >= 0; i--) if (path[i] !== "/") break;
|
|
47
|
+
return path.slice(0, i + 1);
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { href };
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
|
|
2
|
+
//#region lib/router/history.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Actions represent the type of change to a location value.
|
|
5
|
+
*/
|
|
6
|
+
declare enum Action {
|
|
7
|
+
/**
|
|
8
|
+
* A POP indicates a change to an arbitrary index in the history stack, such
|
|
9
|
+
* as a back or forward navigation. It does not describe the direction of the
|
|
10
|
+
* navigation, only that the current index changed.
|
|
11
|
+
*
|
|
12
|
+
* Note: This is the default action for newly created history objects.
|
|
13
|
+
*/
|
|
14
|
+
Pop = "POP",
|
|
15
|
+
/**
|
|
16
|
+
* A PUSH indicates a new entry being added to the history stack, such as when
|
|
17
|
+
* a link is clicked and a new page loads. When this happens, all subsequent
|
|
18
|
+
* entries in the stack are lost.
|
|
19
|
+
*/
|
|
20
|
+
Push = "PUSH",
|
|
21
|
+
/**
|
|
22
|
+
* A REPLACE indicates the entry at the current index in the history stack
|
|
23
|
+
* being replaced by a new one.
|
|
24
|
+
*/
|
|
25
|
+
Replace = "REPLACE"
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The pathname, search, and hash values of a URL.
|
|
29
|
+
*/
|
|
30
|
+
interface Path {
|
|
31
|
+
/**
|
|
32
|
+
* A URL pathname, beginning with a /.
|
|
33
|
+
*/
|
|
34
|
+
pathname: string;
|
|
35
|
+
/**
|
|
36
|
+
* A URL search string, beginning with a ?.
|
|
37
|
+
*/
|
|
38
|
+
search: string;
|
|
39
|
+
/**
|
|
40
|
+
* A URL fragment identifier, beginning with a #.
|
|
41
|
+
*/
|
|
42
|
+
hash: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* An entry in a history stack. A location contains information about the
|
|
46
|
+
* URL path, as well as possibly some arbitrary state and a key.
|
|
47
|
+
*/
|
|
48
|
+
interface Location<State = any> extends Path {
|
|
49
|
+
/**
|
|
50
|
+
* A value of arbitrary data associated with this location.
|
|
51
|
+
*/
|
|
52
|
+
state: State;
|
|
53
|
+
/**
|
|
54
|
+
* A unique string associated with this location. May be used to safely store
|
|
55
|
+
* and retrieve data in some other storage API, like `localStorage`.
|
|
56
|
+
*
|
|
57
|
+
* Note: This value is always "default" on the initial location.
|
|
58
|
+
*/
|
|
59
|
+
key: string;
|
|
60
|
+
/**
|
|
61
|
+
* The masked location displayed in the URL bar, which differs from the URL the
|
|
62
|
+
* router is operating on
|
|
63
|
+
*/
|
|
64
|
+
mask?: Path;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A change to the current location.
|
|
68
|
+
*/
|
|
69
|
+
interface Update {
|
|
70
|
+
/**
|
|
71
|
+
* The action that triggered the change.
|
|
72
|
+
*/
|
|
73
|
+
action: Action;
|
|
74
|
+
/**
|
|
75
|
+
* The new location.
|
|
76
|
+
*/
|
|
77
|
+
location: Location;
|
|
78
|
+
/**
|
|
79
|
+
* The delta between this location and the former location in the history stack
|
|
80
|
+
*/
|
|
81
|
+
delta: number | null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A function that receives notifications about location changes.
|
|
85
|
+
*/
|
|
86
|
+
interface Listener {
|
|
87
|
+
(update: Update): void;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Describes a location that is the destination of some navigation used in
|
|
91
|
+
* {@link Link}, {@link useNavigate}, etc.
|
|
92
|
+
*/
|
|
93
|
+
type To = string | Partial<Path>;
|
|
94
|
+
/**
|
|
95
|
+
* A history is an interface to the navigation stack. The history serves as the
|
|
96
|
+
* source of truth for the current location, as well as provides a set of
|
|
97
|
+
* methods that may be used to change it.
|
|
98
|
+
*
|
|
99
|
+
* It is similar to the DOM's `window.history` object, but with a smaller, more
|
|
100
|
+
* focused API.
|
|
101
|
+
*/
|
|
102
|
+
interface History {
|
|
103
|
+
/**
|
|
104
|
+
* The last action that modified the current location. This will always be
|
|
105
|
+
* Action.Pop when a history instance is first created. This value is mutable.
|
|
106
|
+
*/
|
|
107
|
+
readonly action: Action;
|
|
108
|
+
/**
|
|
109
|
+
* The current location. This value is mutable.
|
|
110
|
+
*/
|
|
111
|
+
readonly location: Location;
|
|
112
|
+
/**
|
|
113
|
+
* Returns a valid href for the given `to` value that may be used as
|
|
114
|
+
* the value of an <a href> attribute.
|
|
115
|
+
*
|
|
116
|
+
* @param to - The destination URL
|
|
117
|
+
*/
|
|
118
|
+
createHref(to: To): string;
|
|
119
|
+
/**
|
|
120
|
+
* Returns a URL for the given `to` value
|
|
121
|
+
*
|
|
122
|
+
* @param to - The destination URL
|
|
123
|
+
*/
|
|
124
|
+
createURL(to: To): URL;
|
|
125
|
+
/**
|
|
126
|
+
* Encode a location the same way window.history would do (no-op for memory
|
|
127
|
+
* history) so we ensure our PUSH/REPLACE navigations for data routers
|
|
128
|
+
* behave the same as POP
|
|
129
|
+
*
|
|
130
|
+
* @param to Unencoded path
|
|
131
|
+
*/
|
|
132
|
+
encodeLocation(to: To): Path;
|
|
133
|
+
/**
|
|
134
|
+
* Pushes a new location onto the history stack, increasing its length by one.
|
|
135
|
+
* If there were any entries in the stack after the current one, they are
|
|
136
|
+
* lost.
|
|
137
|
+
*
|
|
138
|
+
* @param to - The new URL
|
|
139
|
+
* @param state - Data to associate with the new location
|
|
140
|
+
*/
|
|
141
|
+
push(to: To, state?: any): void;
|
|
142
|
+
/**
|
|
143
|
+
* Replaces the current location in the history stack with a new one. The
|
|
144
|
+
* location that was replaced will no longer be available.
|
|
145
|
+
*
|
|
146
|
+
* @param to - The new URL
|
|
147
|
+
* @param state - Data to associate with the new location
|
|
148
|
+
*/
|
|
149
|
+
replace(to: To, state?: any): void;
|
|
150
|
+
/**
|
|
151
|
+
* Navigates `n` entries backward/forward in the history stack relative to the
|
|
152
|
+
* current index. For example, a "back" navigation would use go(-1).
|
|
153
|
+
*
|
|
154
|
+
* @param delta - The delta in the stack index
|
|
155
|
+
*/
|
|
156
|
+
go(delta: number): void;
|
|
157
|
+
/**
|
|
158
|
+
* Sets up a listener that will be called whenever the current location
|
|
159
|
+
* changes.
|
|
160
|
+
*
|
|
161
|
+
* @param listener - A function that will be called when the location changes
|
|
162
|
+
* @returns unlisten - A function that may be used to stop listening
|
|
163
|
+
*/
|
|
164
|
+
listen(listener: Listener): () => void;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* A user-supplied object that describes a location. Used when providing
|
|
168
|
+
* entries to `createMemoryHistory` via its `initialEntries` option.
|
|
169
|
+
*/
|
|
170
|
+
type InitialEntry = string | Partial<Location>;
|
|
171
|
+
type MemoryHistoryOptions = {
|
|
172
|
+
initialEntries?: InitialEntry[];
|
|
173
|
+
initialIndex?: number;
|
|
174
|
+
v5Compat?: boolean;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* A memory history stores locations in memory. This is useful in stateful
|
|
178
|
+
* environments where there is no web browser, such as node tests or React
|
|
179
|
+
* Native.
|
|
180
|
+
*/
|
|
181
|
+
interface MemoryHistory extends History {
|
|
182
|
+
/**
|
|
183
|
+
* The current index in the history stack.
|
|
184
|
+
*/
|
|
185
|
+
readonly index: number;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Memory history stores the current location in memory. It is designed for use
|
|
189
|
+
* in stateful non-browser environments like tests and React Native.
|
|
190
|
+
*/
|
|
191
|
+
declare function createMemoryHistory(options?: MemoryHistoryOptions): MemoryHistory;
|
|
192
|
+
/**
|
|
193
|
+
* A browser history stores the current location in regular URLs in a web
|
|
194
|
+
* browser environment. This is the standard for most web apps and provides the
|
|
195
|
+
* cleanest URLs the browser's address bar.
|
|
196
|
+
*
|
|
197
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#browserhistory
|
|
198
|
+
*/
|
|
199
|
+
interface BrowserHistory extends UrlHistory {}
|
|
200
|
+
type BrowserHistoryOptions = UrlHistoryOptions;
|
|
201
|
+
/**
|
|
202
|
+
* Browser history stores the location in regular URLs. This is the standard for
|
|
203
|
+
* most web apps, but it requires some configuration on the server to ensure you
|
|
204
|
+
* serve the same app at multiple URLs.
|
|
205
|
+
*
|
|
206
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
|
|
207
|
+
*/
|
|
208
|
+
declare function createBrowserHistory(options?: BrowserHistoryOptions): BrowserHistory;
|
|
209
|
+
/**
|
|
210
|
+
* A hash history stores the current location in the fragment identifier portion
|
|
211
|
+
* of the URL in a web browser environment.
|
|
212
|
+
*
|
|
213
|
+
* This is ideal for apps that do not control the server for some reason
|
|
214
|
+
* (because the fragment identifier is never sent to the server), including some
|
|
215
|
+
* shared hosting environments that do not provide fine-grained controls over
|
|
216
|
+
* which pages are served at which URLs.
|
|
217
|
+
*
|
|
218
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#hashhistory
|
|
219
|
+
*/
|
|
220
|
+
interface HashHistory extends UrlHistory {}
|
|
221
|
+
type HashHistoryOptions = UrlHistoryOptions;
|
|
222
|
+
/**
|
|
223
|
+
* Hash history stores the location in window.location.hash. This makes it ideal
|
|
224
|
+
* for situations where you don't want to send the location to the server for
|
|
225
|
+
* some reason, either because you do cannot configure it or the URL space is
|
|
226
|
+
* reserved for something else.
|
|
227
|
+
*
|
|
228
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
|
|
229
|
+
*/
|
|
230
|
+
declare function createHashHistory(options?: HashHistoryOptions): HashHistory;
|
|
231
|
+
/**
|
|
232
|
+
* @private
|
|
233
|
+
*/
|
|
234
|
+
declare function invariant(value: boolean, message?: string): asserts value;
|
|
235
|
+
declare function invariant<T>(value: T | null | undefined, message?: string): asserts value is T;
|
|
236
|
+
/**
|
|
237
|
+
* Creates a string URL path from the given pathname, search, and hash components.
|
|
238
|
+
*
|
|
239
|
+
* @category Utils
|
|
240
|
+
*/
|
|
241
|
+
declare function createPath({
|
|
242
|
+
pathname,
|
|
243
|
+
search,
|
|
244
|
+
hash
|
|
245
|
+
}: Partial<Path>): string;
|
|
246
|
+
/**
|
|
247
|
+
* Parses a string URL path into its separate pathname, search, and hash components.
|
|
248
|
+
*
|
|
249
|
+
* @category Utils
|
|
250
|
+
*/
|
|
251
|
+
declare function parsePath(path: string): Partial<Path>;
|
|
252
|
+
interface UrlHistory extends History {}
|
|
253
|
+
type UrlHistoryOptions = {
|
|
254
|
+
window?: Window;
|
|
255
|
+
v5Compat?: boolean;
|
|
256
|
+
};
|
|
257
|
+
//#endregion
|
|
258
|
+
export { Action, History, InitialEntry, Location, Path, To, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, invariant, parsePath };
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-router v8.0.0-pre.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
//#region lib/router/history.ts
|
|
12
|
+
/**
|
|
13
|
+
* Actions represent the type of change to a location value.
|
|
14
|
+
*/
|
|
15
|
+
let Action = /* @__PURE__ */ function(Action) {
|
|
16
|
+
/**
|
|
17
|
+
* A POP indicates a change to an arbitrary index in the history stack, such
|
|
18
|
+
* as a back or forward navigation. It does not describe the direction of the
|
|
19
|
+
* navigation, only that the current index changed.
|
|
20
|
+
*
|
|
21
|
+
* Note: This is the default action for newly created history objects.
|
|
22
|
+
*/
|
|
23
|
+
Action["Pop"] = "POP";
|
|
24
|
+
/**
|
|
25
|
+
* A PUSH indicates a new entry being added to the history stack, such as when
|
|
26
|
+
* a link is clicked and a new page loads. When this happens, all subsequent
|
|
27
|
+
* entries in the stack are lost.
|
|
28
|
+
*/
|
|
29
|
+
Action["Push"] = "PUSH";
|
|
30
|
+
/**
|
|
31
|
+
* A REPLACE indicates the entry at the current index in the history stack
|
|
32
|
+
* being replaced by a new one.
|
|
33
|
+
*/
|
|
34
|
+
Action["Replace"] = "REPLACE";
|
|
35
|
+
return Action;
|
|
36
|
+
}({});
|
|
37
|
+
const PopStateEventType = "popstate";
|
|
38
|
+
function isLocation(obj) {
|
|
39
|
+
return typeof obj === "object" && obj != null && "pathname" in obj && "search" in obj && "hash" in obj && "state" in obj && "key" in obj;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Memory history stores the current location in memory. It is designed for use
|
|
43
|
+
* in stateful non-browser environments like tests and React Native.
|
|
44
|
+
*/
|
|
45
|
+
function createMemoryHistory(options = {}) {
|
|
46
|
+
let { initialEntries = ["/"], initialIndex, v5Compat = false } = options;
|
|
47
|
+
let entries;
|
|
48
|
+
entries = initialEntries.map((entry, index) => createMemoryLocation(entry, typeof entry === "string" ? null : entry.state, index === 0 ? "default" : void 0, typeof entry === "string" ? void 0 : entry.mask));
|
|
49
|
+
let index = clampIndex(initialIndex == null ? entries.length - 1 : initialIndex);
|
|
50
|
+
let action = "POP";
|
|
51
|
+
let listener = null;
|
|
52
|
+
function clampIndex(n) {
|
|
53
|
+
return Math.min(Math.max(n, 0), entries.length - 1);
|
|
54
|
+
}
|
|
55
|
+
function getCurrentLocation() {
|
|
56
|
+
return entries[index];
|
|
57
|
+
}
|
|
58
|
+
function createMemoryLocation(to, state = null, key, mask) {
|
|
59
|
+
let location = createLocation(entries ? getCurrentLocation().pathname : "/", to, state, key, mask);
|
|
60
|
+
warning(location.pathname.charAt(0) === "/", `relative pathnames are not supported in memory history: ${JSON.stringify(to)}`);
|
|
61
|
+
return location;
|
|
62
|
+
}
|
|
63
|
+
function createHref(to) {
|
|
64
|
+
return typeof to === "string" ? to : createPath(to);
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
get index() {
|
|
68
|
+
return index;
|
|
69
|
+
},
|
|
70
|
+
get action() {
|
|
71
|
+
return action;
|
|
72
|
+
},
|
|
73
|
+
get location() {
|
|
74
|
+
return getCurrentLocation();
|
|
75
|
+
},
|
|
76
|
+
createHref,
|
|
77
|
+
createURL(to) {
|
|
78
|
+
return new URL(createHref(to), "http://localhost");
|
|
79
|
+
},
|
|
80
|
+
encodeLocation(to) {
|
|
81
|
+
let path = typeof to === "string" ? parsePath(to) : to;
|
|
82
|
+
return {
|
|
83
|
+
pathname: path.pathname || "",
|
|
84
|
+
search: path.search || "",
|
|
85
|
+
hash: path.hash || ""
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
push(to, state) {
|
|
89
|
+
action = "PUSH";
|
|
90
|
+
let nextLocation = isLocation(to) ? to : createMemoryLocation(to, state);
|
|
91
|
+
index += 1;
|
|
92
|
+
entries.splice(index, entries.length, nextLocation);
|
|
93
|
+
if (v5Compat && listener) listener({
|
|
94
|
+
action,
|
|
95
|
+
location: nextLocation,
|
|
96
|
+
delta: 1
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
replace(to, state) {
|
|
100
|
+
action = "REPLACE";
|
|
101
|
+
let nextLocation = isLocation(to) ? to : createMemoryLocation(to, state);
|
|
102
|
+
entries[index] = nextLocation;
|
|
103
|
+
if (v5Compat && listener) listener({
|
|
104
|
+
action,
|
|
105
|
+
location: nextLocation,
|
|
106
|
+
delta: 0
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
go(delta) {
|
|
110
|
+
action = "POP";
|
|
111
|
+
let nextIndex = clampIndex(index + delta);
|
|
112
|
+
let nextLocation = entries[nextIndex];
|
|
113
|
+
index = nextIndex;
|
|
114
|
+
if (listener) listener({
|
|
115
|
+
action,
|
|
116
|
+
location: nextLocation,
|
|
117
|
+
delta
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
listen(fn) {
|
|
121
|
+
listener = fn;
|
|
122
|
+
return () => {
|
|
123
|
+
listener = null;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Browser history stores the location in regular URLs. This is the standard for
|
|
130
|
+
* most web apps, but it requires some configuration on the server to ensure you
|
|
131
|
+
* serve the same app at multiple URLs.
|
|
132
|
+
*
|
|
133
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
|
|
134
|
+
*/
|
|
135
|
+
function createBrowserHistory(options = {}) {
|
|
136
|
+
function createBrowserLocation(window, globalHistory) {
|
|
137
|
+
let maskedLocation = globalHistory.state?.masked;
|
|
138
|
+
let { pathname, search, hash } = maskedLocation || window.location;
|
|
139
|
+
return createLocation("", {
|
|
140
|
+
pathname,
|
|
141
|
+
search,
|
|
142
|
+
hash
|
|
143
|
+
}, globalHistory.state && globalHistory.state.usr || null, globalHistory.state && globalHistory.state.key || "default", maskedLocation ? {
|
|
144
|
+
pathname: window.location.pathname,
|
|
145
|
+
search: window.location.search,
|
|
146
|
+
hash: window.location.hash
|
|
147
|
+
} : void 0);
|
|
148
|
+
}
|
|
149
|
+
function createBrowserHref(window, to) {
|
|
150
|
+
return typeof to === "string" ? to : createPath(to);
|
|
151
|
+
}
|
|
152
|
+
return getUrlBasedHistory(createBrowserLocation, createBrowserHref, null, options);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Hash history stores the location in window.location.hash. This makes it ideal
|
|
156
|
+
* for situations where you don't want to send the location to the server for
|
|
157
|
+
* some reason, either because you do cannot configure it or the URL space is
|
|
158
|
+
* reserved for something else.
|
|
159
|
+
*
|
|
160
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
|
|
161
|
+
*/
|
|
162
|
+
function createHashHistory(options = {}) {
|
|
163
|
+
function createHashLocation(window, globalHistory) {
|
|
164
|
+
let { pathname = "/", search = "", hash = "" } = parsePath(window.location.hash.substring(1));
|
|
165
|
+
if (!pathname.startsWith("/") && !pathname.startsWith(".")) pathname = "/" + pathname;
|
|
166
|
+
return createLocation("", {
|
|
167
|
+
pathname,
|
|
168
|
+
search,
|
|
169
|
+
hash
|
|
170
|
+
}, globalHistory.state && globalHistory.state.usr || null, globalHistory.state && globalHistory.state.key || "default");
|
|
171
|
+
}
|
|
172
|
+
function createHashHref(window, to) {
|
|
173
|
+
let base = window.document.querySelector("base");
|
|
174
|
+
let href = "";
|
|
175
|
+
if (base && base.getAttribute("href")) {
|
|
176
|
+
let url = window.location.href;
|
|
177
|
+
let hashIndex = url.indexOf("#");
|
|
178
|
+
href = hashIndex === -1 ? url : url.slice(0, hashIndex);
|
|
179
|
+
}
|
|
180
|
+
return href + "#" + (typeof to === "string" ? to : createPath(to));
|
|
181
|
+
}
|
|
182
|
+
function validateHashLocation(location, to) {
|
|
183
|
+
warning(location.pathname.charAt(0) === "/", `relative pathnames are not supported in hash history.push(${JSON.stringify(to)})`);
|
|
184
|
+
}
|
|
185
|
+
return getUrlBasedHistory(createHashLocation, createHashHref, validateHashLocation, options);
|
|
186
|
+
}
|
|
187
|
+
function invariant(value, message) {
|
|
188
|
+
if (value === false || value === null || typeof value === "undefined") throw new Error(message);
|
|
189
|
+
}
|
|
190
|
+
function warning(cond, message) {
|
|
191
|
+
if (!cond) {
|
|
192
|
+
if (typeof console !== "undefined") console.warn(message);
|
|
193
|
+
try {
|
|
194
|
+
throw new Error(message);
|
|
195
|
+
} catch (e) {}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function createKey() {
|
|
199
|
+
return Math.random().toString(36).substring(2, 10);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* For browser-based histories, we combine the state and key into an object
|
|
203
|
+
*/
|
|
204
|
+
function getHistoryState(location, index) {
|
|
205
|
+
return {
|
|
206
|
+
usr: location.state,
|
|
207
|
+
key: location.key,
|
|
208
|
+
idx: index,
|
|
209
|
+
masked: location.mask ? {
|
|
210
|
+
pathname: location.pathname,
|
|
211
|
+
search: location.search,
|
|
212
|
+
hash: location.hash
|
|
213
|
+
} : void 0
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Creates a Location object with a unique key from the given Path
|
|
218
|
+
*/
|
|
219
|
+
function createLocation(current, to, state = null, key, mask) {
|
|
220
|
+
return {
|
|
221
|
+
pathname: typeof current === "string" ? current : current.pathname,
|
|
222
|
+
search: "",
|
|
223
|
+
hash: "",
|
|
224
|
+
...typeof to === "string" ? parsePath(to) : to,
|
|
225
|
+
state,
|
|
226
|
+
key: to && to.key || key || createKey(),
|
|
227
|
+
mask
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Creates a string URL path from the given pathname, search, and hash components.
|
|
232
|
+
*
|
|
233
|
+
* @category Utils
|
|
234
|
+
*/
|
|
235
|
+
function createPath({ pathname = "/", search = "", hash = "" }) {
|
|
236
|
+
if (search && search !== "?") pathname += search.charAt(0) === "?" ? search : "?" + search;
|
|
237
|
+
if (hash && hash !== "#") pathname += hash.charAt(0) === "#" ? hash : "#" + hash;
|
|
238
|
+
return pathname;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Parses a string URL path into its separate pathname, search, and hash components.
|
|
242
|
+
*
|
|
243
|
+
* @category Utils
|
|
244
|
+
*/
|
|
245
|
+
function parsePath(path) {
|
|
246
|
+
let parsedPath = {};
|
|
247
|
+
if (path) {
|
|
248
|
+
let hashIndex = path.indexOf("#");
|
|
249
|
+
if (hashIndex >= 0) {
|
|
250
|
+
parsedPath.hash = path.substring(hashIndex);
|
|
251
|
+
path = path.substring(0, hashIndex);
|
|
252
|
+
}
|
|
253
|
+
let searchIndex = path.indexOf("?");
|
|
254
|
+
if (searchIndex >= 0) {
|
|
255
|
+
parsedPath.search = path.substring(searchIndex);
|
|
256
|
+
path = path.substring(0, searchIndex);
|
|
257
|
+
}
|
|
258
|
+
if (path) parsedPath.pathname = path;
|
|
259
|
+
}
|
|
260
|
+
return parsedPath;
|
|
261
|
+
}
|
|
262
|
+
function getUrlBasedHistory(getLocation, createHref, validateLocation, options = {}) {
|
|
263
|
+
let { window = document.defaultView, v5Compat = false } = options;
|
|
264
|
+
let globalHistory = window.history;
|
|
265
|
+
let action = "POP";
|
|
266
|
+
let listener = null;
|
|
267
|
+
let index = getIndex();
|
|
268
|
+
if (index == null) {
|
|
269
|
+
index = 0;
|
|
270
|
+
globalHistory.replaceState({
|
|
271
|
+
...globalHistory.state,
|
|
272
|
+
idx: index
|
|
273
|
+
}, "");
|
|
274
|
+
}
|
|
275
|
+
function getIndex() {
|
|
276
|
+
return (globalHistory.state || { idx: null }).idx;
|
|
277
|
+
}
|
|
278
|
+
function handlePop() {
|
|
279
|
+
action = "POP";
|
|
280
|
+
let nextIndex = getIndex();
|
|
281
|
+
let delta = nextIndex == null ? null : nextIndex - index;
|
|
282
|
+
index = nextIndex;
|
|
283
|
+
if (listener) listener({
|
|
284
|
+
action,
|
|
285
|
+
location: history.location,
|
|
286
|
+
delta
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
function push(to, state) {
|
|
290
|
+
action = "PUSH";
|
|
291
|
+
let location = isLocation(to) ? to : createLocation(history.location, to, state);
|
|
292
|
+
if (validateLocation) validateLocation(location, to);
|
|
293
|
+
index = getIndex() + 1;
|
|
294
|
+
let historyState = getHistoryState(location, index);
|
|
295
|
+
let url = history.createHref(location.mask || location);
|
|
296
|
+
try {
|
|
297
|
+
globalHistory.pushState(historyState, "", url);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
if (error instanceof DOMException && error.name === "DataCloneError") throw error;
|
|
300
|
+
window.location.assign(url);
|
|
301
|
+
}
|
|
302
|
+
if (v5Compat && listener) listener({
|
|
303
|
+
action,
|
|
304
|
+
location: history.location,
|
|
305
|
+
delta: 1
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
function replace(to, state) {
|
|
309
|
+
action = "REPLACE";
|
|
310
|
+
let location = isLocation(to) ? to : createLocation(history.location, to, state);
|
|
311
|
+
if (validateLocation) validateLocation(location, to);
|
|
312
|
+
index = getIndex();
|
|
313
|
+
let historyState = getHistoryState(location, index);
|
|
314
|
+
let url = history.createHref(location.mask || location);
|
|
315
|
+
globalHistory.replaceState(historyState, "", url);
|
|
316
|
+
if (v5Compat && listener) listener({
|
|
317
|
+
action,
|
|
318
|
+
location: history.location,
|
|
319
|
+
delta: 0
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
function createURL(to) {
|
|
323
|
+
return createBrowserURLImpl(window, to);
|
|
324
|
+
}
|
|
325
|
+
let history = {
|
|
326
|
+
get action() {
|
|
327
|
+
return action;
|
|
328
|
+
},
|
|
329
|
+
get location() {
|
|
330
|
+
return getLocation(window, globalHistory);
|
|
331
|
+
},
|
|
332
|
+
listen(fn) {
|
|
333
|
+
if (listener) throw new Error("A history only accepts one active listener");
|
|
334
|
+
window.addEventListener(PopStateEventType, handlePop);
|
|
335
|
+
listener = fn;
|
|
336
|
+
return () => {
|
|
337
|
+
window.removeEventListener(PopStateEventType, handlePop);
|
|
338
|
+
listener = null;
|
|
339
|
+
};
|
|
340
|
+
},
|
|
341
|
+
createHref(to) {
|
|
342
|
+
return createHref(window, to);
|
|
343
|
+
},
|
|
344
|
+
createURL,
|
|
345
|
+
encodeLocation(to) {
|
|
346
|
+
let url = createURL(to);
|
|
347
|
+
return {
|
|
348
|
+
pathname: url.pathname,
|
|
349
|
+
search: url.search,
|
|
350
|
+
hash: url.hash
|
|
351
|
+
};
|
|
352
|
+
},
|
|
353
|
+
push,
|
|
354
|
+
replace,
|
|
355
|
+
go(n) {
|
|
356
|
+
return globalHistory.go(n);
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
return history;
|
|
360
|
+
}
|
|
361
|
+
function createBrowserURLImpl(windowImpl, to, isAbsolute = false) {
|
|
362
|
+
let base = "http://localhost";
|
|
363
|
+
if (windowImpl) base = windowImpl.location.origin !== "null" ? windowImpl.location.origin : windowImpl.location.href;
|
|
364
|
+
invariant(base, "No window.location.(origin|href) available to create URL");
|
|
365
|
+
let href = typeof to === "string" ? to : createPath(to);
|
|
366
|
+
href = href.replace(/ $/, "%20");
|
|
367
|
+
if (!isAbsolute && href.startsWith("//")) href = base + href;
|
|
368
|
+
return new URL(href, base);
|
|
369
|
+
}
|
|
370
|
+
//#endregion
|
|
371
|
+
export { Action, createBrowserHistory, createBrowserURLImpl, createHashHistory, createLocation, createMemoryHistory, createPath, invariant, parsePath, warning };
|