react-router 7.15.1 → 8.3.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 +181 -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 +1789 -1657
- package/dist/development/index-react-server.js +3074 -3674
- package/dist/development/index.d.ts +41 -1469
- package/dist/development/index.js +36 -2621
- package/dist/development/lib/actions.js +50 -0
- package/dist/development/lib/components.d.ts +1030 -0
- package/dist/development/lib/components.js +841 -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 +2054 -0
- package/dist/development/lib/dom/lib.js +1272 -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 +198 -0
- package/dist/development/lib/dom/ssr/components.js +589 -0
- package/dist/development/lib/dom/ssr/data.js +29 -0
- package/dist/development/lib/dom/ssr/entry.d.ts +60 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.js +87 -0
- package/dist/development/lib/dom/ssr/fallback.js +33 -0
- package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/development/lib/dom/ssr/fog-of-war.js +185 -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 +75 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.js +121 -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 +48 -0
- package/dist/development/lib/dom/ssr/server.js +69 -0
- package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/development/lib/dom/ssr/single-fetch.js +345 -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 +150 -0
- package/dist/development/lib/errors.js +29 -0
- package/dist/development/lib/hooks.d.ts +974 -0
- package/dist/development/lib/hooks.js +1415 -0
- package/dist/development/lib/href.d.ts +36 -0
- package/dist/development/lib/href.js +70 -0
- package/dist/development/lib/router/history.d.ts +264 -0
- package/dist/development/lib/router/history.js +378 -0
- package/dist/development/lib/router/instrumentation.d.ts +111 -0
- package/dist/development/lib/router/instrumentation.js +290 -0
- package/dist/development/lib/router/links.d.ts +114 -0
- package/dist/development/lib/router/router.d.ts +663 -0
- package/dist/development/lib/router/router.js +2988 -0
- package/dist/development/lib/router/url.js +18 -0
- package/dist/development/lib/router/utils.d.ts +960 -0
- package/dist/development/lib/router/utils.js +881 -0
- package/dist/development/lib/rsc/browser.d.ts +137 -0
- package/dist/development/lib/rsc/browser.js +612 -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 +97 -0
- package/dist/development/lib/rsc/route-modules.js +27 -0
- package/dist/development/lib/rsc/server.rsc.d.ts +224 -0
- package/dist/development/lib/rsc/server.ssr.d.ts +152 -0
- package/dist/development/lib/rsc/server.ssr.js +419 -0
- package/dist/development/lib/server-runtime/build.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.d.ts +92 -0
- package/dist/development/lib/server-runtime/cookies.js +153 -0
- package/dist/development/lib/server-runtime/crypto.js +43 -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 +75 -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 +22 -0
- package/dist/development/lib/server-runtime/server.js +364 -0
- package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +33 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +53 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +29 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +58 -0
- package/dist/development/lib/server-runtime/sessions.d.ts +174 -0
- package/dist/development/lib/server-runtime/sessions.js +115 -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 +28 -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 +179 -0
- package/dist/development/vendor/turbo-stream-v2/unflatten.js +199 -0
- package/dist/development/vendor/turbo-stream-v2/utils.js +39 -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 +1789 -1657
- package/dist/production/index-react-server.js +3065 -3674
- package/dist/production/index.d.ts +41 -1469
- package/dist/production/index.js +36 -2621
- package/dist/production/lib/actions.js +50 -0
- package/dist/production/lib/components.d.ts +1030 -0
- package/dist/production/lib/components.js +841 -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 +2054 -0
- package/dist/production/lib/dom/lib.js +1272 -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 +198 -0
- package/dist/production/lib/dom/ssr/components.js +589 -0
- package/dist/production/lib/dom/ssr/data.js +29 -0
- package/dist/production/lib/dom/ssr/entry.d.ts +60 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.js +87 -0
- package/dist/production/lib/dom/ssr/fallback.js +23 -0
- package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/production/lib/dom/ssr/fog-of-war.js +185 -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 +75 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.js +121 -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 +48 -0
- package/dist/production/lib/dom/ssr/server.js +69 -0
- package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/production/lib/dom/ssr/single-fetch.js +345 -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 +150 -0
- package/dist/production/lib/errors.js +29 -0
- package/dist/production/lib/hooks.d.ts +974 -0
- package/dist/production/lib/hooks.js +1400 -0
- package/dist/production/lib/href.d.ts +36 -0
- package/dist/production/lib/href.js +70 -0
- package/dist/production/lib/router/history.d.ts +264 -0
- package/dist/production/lib/router/history.js +378 -0
- package/dist/production/lib/router/instrumentation.d.ts +111 -0
- package/dist/production/lib/router/instrumentation.js +290 -0
- package/dist/production/lib/router/links.d.ts +114 -0
- package/dist/production/lib/router/router.d.ts +663 -0
- package/dist/production/lib/router/router.js +2988 -0
- package/dist/production/lib/router/url.js +18 -0
- package/dist/production/lib/router/utils.d.ts +960 -0
- package/dist/production/lib/router/utils.js +872 -0
- package/dist/production/lib/rsc/browser.d.ts +137 -0
- package/dist/production/lib/rsc/browser.js +612 -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 +97 -0
- package/dist/production/lib/rsc/route-modules.js +27 -0
- package/dist/production/lib/rsc/server.rsc.d.ts +224 -0
- package/dist/production/lib/rsc/server.ssr.d.ts +152 -0
- package/dist/production/lib/rsc/server.ssr.js +419 -0
- package/dist/production/lib/server-runtime/build.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.d.ts +92 -0
- package/dist/production/lib/server-runtime/cookies.js +153 -0
- package/dist/production/lib/server-runtime/crypto.js +43 -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 +75 -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 +22 -0
- package/dist/production/lib/server-runtime/server.js +364 -0
- package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +33 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +53 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +29 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +58 -0
- package/dist/production/lib/server-runtime/sessions.d.ts +174 -0
- package/dist/production/lib/server-runtime/sessions.js +115 -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 +28 -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 +179 -0
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +199 -0
- package/dist/production/vendor/turbo-stream-v2/utils.js +39 -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 +142 -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 +165 -0
- package/docs/how-to/index.md +4 -0
- package/docs/how-to/instrumentation.md +661 -0
- package/docs/how-to/meta.md +40 -0
- package/docs/how-to/middleware.md +647 -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 +951 -0
- package/docs/how-to/resource-routes.md +126 -0
- package/docs/how-to/route-module-type-safety.md +85 -0
- package/docs/how-to/search-params.md +4 -0
- package/docs/how-to/security.md +39 -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 +36 -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 +56 -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 +268 -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 +174 -0
- package/docs/start/framework/data-loading.md +201 -0
- package/docs/start/framework/deploying.md +104 -0
- package/docs/start/framework/index.md +4 -0
- package/docs/start/framework/installation.md +41 -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 +200 -0
- package/docs/upgrading/component-routes.md +363 -0
- package/docs/upgrading/future.md +111 -0
- package/docs/upgrading/index.md +4 -0
- package/docs/upgrading/router-provider.md +445 -0
- package/docs/upgrading/v7.md +460 -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,36 @@
|
|
|
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
|
+
* Param values are percent-encoded for use in a path segment: characters that
|
|
12
|
+
* would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
|
|
13
|
+
* are escaped, while characters that RFC 3986 allows literally in a path
|
|
14
|
+
* segment (`$ & + , ; = : @`) are kept as-is. Note this differs from query-string
|
|
15
|
+
* encoding (`encodeURIComponent`/`URLSearchParams`), where those characters are
|
|
16
|
+
* delimiters and must be escaped. Splat (`*`) values are encoded per segment,
|
|
17
|
+
* preserving `/` separators.
|
|
18
|
+
*
|
|
19
|
+
* See [RFC 3986 §3.3](https://datatracker.ietf.org/doc/html/rfc3986#section-3.3)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const h = href("/:lang?/about", { lang: "en" })
|
|
23
|
+
* // -> `/en/about`
|
|
24
|
+
*
|
|
25
|
+
* <Link to={href("/products/:id", { id: "abc123" })} />
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
* @category Utils
|
|
29
|
+
* @mode framework
|
|
30
|
+
* @param path The route path to resolve
|
|
31
|
+
* @param args The route params to use when resolving the path
|
|
32
|
+
* @returns The resolved URL path
|
|
33
|
+
*/
|
|
34
|
+
declare function href<Path extends keyof Args>(path: Path, ...args: Args[Path]): string;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { href };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-router v8.3.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
|
+
import { encodePathParam } from "./router/utils.js";
|
|
12
|
+
//#region lib/href.ts
|
|
13
|
+
function stringify(p) {
|
|
14
|
+
return p == null ? "" : typeof p === "string" ? p : String(p);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns a resolved URL path for the specified route.
|
|
18
|
+
*
|
|
19
|
+
* Param values are percent-encoded for use in a path segment: characters that
|
|
20
|
+
* would change the URL structure (`/`, `?`, `#`, `%`, whitespace, non-ASCII)
|
|
21
|
+
* are escaped, while characters that RFC 3986 allows literally in a path
|
|
22
|
+
* segment (`$ & + , ; = : @`) are kept as-is. Note this differs from query-string
|
|
23
|
+
* encoding (`encodeURIComponent`/`URLSearchParams`), where those characters are
|
|
24
|
+
* delimiters and must be escaped. Splat (`*`) values are encoded per segment,
|
|
25
|
+
* preserving `/` separators.
|
|
26
|
+
*
|
|
27
|
+
* See [RFC 3986 §3.3](https://datatracker.ietf.org/doc/html/rfc3986#section-3.3)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const h = href("/:lang?/about", { lang: "en" })
|
|
31
|
+
* // -> `/en/about`
|
|
32
|
+
*
|
|
33
|
+
* <Link to={href("/products/:id", { id: "abc123" })} />
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
* @category Utils
|
|
37
|
+
* @mode framework
|
|
38
|
+
* @param path The route path to resolve
|
|
39
|
+
* @param args The route params to use when resolving the path
|
|
40
|
+
* @returns The resolved URL path
|
|
41
|
+
*/
|
|
42
|
+
function href(path, ...args) {
|
|
43
|
+
let params = args[0];
|
|
44
|
+
let result = trimTrailingSplat(path).replace(/\/:([\w-]+)(\?)?/g, (_, param, questionMark) => {
|
|
45
|
+
const isRequired = questionMark === void 0;
|
|
46
|
+
const value = params?.[param];
|
|
47
|
+
if (isRequired && value === void 0) throw new Error(`Path '${path}' requires param '${param}' but it was not provided`);
|
|
48
|
+
return value == null ? "" : "/" + encodePathParam(stringify(value));
|
|
49
|
+
});
|
|
50
|
+
if (path.endsWith("*")) {
|
|
51
|
+
const value = params?.["*"];
|
|
52
|
+
if (value !== void 0) result += "/" + stringify(value).split("/").map(encodePathParam).join("/");
|
|
53
|
+
}
|
|
54
|
+
return result || "/";
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Removes a trailing splat and any number of slashes from the end of the path.
|
|
58
|
+
*
|
|
59
|
+
* Benchmarked to be faster than `path.replace(/\/*\*?$/, "")`, which backtracks.
|
|
60
|
+
*/
|
|
61
|
+
function trimTrailingSplat(path) {
|
|
62
|
+
let i = path.length - 1;
|
|
63
|
+
let char = path[i];
|
|
64
|
+
if (char !== "*" && char !== "/") return path;
|
|
65
|
+
i--;
|
|
66
|
+
for (; i >= 0; i--) if (path[i] !== "/") break;
|
|
67
|
+
return path.slice(0, i + 1);
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { href };
|
|
@@ -0,0 +1,264 @@
|
|
|
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
|
+
* @public
|
|
240
|
+
* @category Utils
|
|
241
|
+
* @param path The pathname, search, and hash components to combine.
|
|
242
|
+
* @returns The combined URL path.
|
|
243
|
+
*/
|
|
244
|
+
declare function createPath({
|
|
245
|
+
pathname,
|
|
246
|
+
search,
|
|
247
|
+
hash
|
|
248
|
+
}: Partial<Path>): string;
|
|
249
|
+
/**
|
|
250
|
+
* Parses a string URL path into its separate pathname, search, and hash components.
|
|
251
|
+
*
|
|
252
|
+
* @public
|
|
253
|
+
* @category Utils
|
|
254
|
+
* @param path The URL path to parse.
|
|
255
|
+
* @returns The parsed pathname, search, and hash components.
|
|
256
|
+
*/
|
|
257
|
+
declare function parsePath(path: string): Partial<Path>;
|
|
258
|
+
interface UrlHistory extends History {}
|
|
259
|
+
type UrlHistoryOptions = {
|
|
260
|
+
window?: Window;
|
|
261
|
+
v5Compat?: boolean;
|
|
262
|
+
};
|
|
263
|
+
//#endregion
|
|
264
|
+
export { Action, History, InitialEntry, Location, Path, To, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, invariant, parsePath };
|