@tanstack/router-core 1.121.0-alpha.3 → 1.121.0-alpha.5
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/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +1 -1
- package/dist/cjs/redirect.cjs +7 -0
- package/dist/cjs/redirect.cjs.map +1 -1
- package/dist/cjs/router.cjs +133 -148
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +0 -4
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/link.d.ts +1 -1
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/redirect.js +7 -0
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/router.d.ts +0 -4
- package/dist/esm/router.js +133 -148
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -1
- package/src/link.ts +1 -1
- package/src/redirect.ts +8 -0
- package/src/router.ts +198 -190
package/dist/cjs/router.d.cts
CHANGED
|
@@ -391,10 +391,6 @@ export interface RouterErrorSerializer<TSerializedError> {
|
|
|
391
391
|
serialize: (err: unknown) => TSerializedError;
|
|
392
392
|
deserialize: (err: TSerializedError) => unknown;
|
|
393
393
|
}
|
|
394
|
-
export interface MatchedRoutesResult {
|
|
395
|
-
matchedRoutes: Array<AnyRoute>;
|
|
396
|
-
routeParams: Record<string, string>;
|
|
397
|
-
}
|
|
398
394
|
export type PreloadRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<Array<AnyRouteMatch> | undefined>;
|
|
399
395
|
export type MatchRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string | undefined = undefined, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>['types']['allParams'];
|
|
400
396
|
export type UpdateFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory, TDehydrated extends Record<string, any>> = (newOptions: RouterConstructorOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>) => void;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type { RootRouteId } from './root.js';
|
|
|
17
17
|
export { BaseRoute, BaseRouteApi, BaseRootRoute } from './route.js';
|
|
18
18
|
export type { AnyPathParams, SearchSchemaInput, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, SearchFilter, SearchMiddlewareContext, SearchMiddleware, ResolveId, InferFullSearchSchema, InferFullSearchSchemaInput, InferAllParams, InferAllContext, MetaDescriptor, RouteLinkEntry, SearchValidator, AnySearchValidator, DefaultSearchValidator, ErrorRouteProps, ErrorComponentProps, NotFoundRouteProps, ResolveParams, ParseParamsFn, StringifyParamsFn, ParamsOptions, UpdatableStaticRouteOption, ContextReturnType, ContextAsyncReturnType, ResolveRouteContext, ResolveLoaderData, RoutePrefix, TrimPath, TrimPathLeft, TrimPathRight, ResolveSearchSchemaFnInput, ResolveSearchSchemaInput, ResolveSearchSchemaFn, ResolveSearchSchema, ResolveFullSearchSchema, ResolveFullSearchSchemaInput, ResolveAllContext, BeforeLoadContextParameter, RouteContextParameter, ResolveAllParamsFromParent, AnyRoute, Route, RouteTypes, FullSearchSchemaOption, RemountDepsOptions, MakeRemountDepsOptionsUnion, ResolveFullPath, AnyRouteWithContext, RouteOptions, FileBaseRouteOptions, BaseRouteOptions, UpdatableRouteOptions, RouteLoaderFn, LoaderFnContext, RouteContextFn, BeforeLoadFn, ContextOptions, RouteContextOptions, BeforeLoadContextOptions, RootRouteOptions, UpdatableRouteOptionsExtensions, RouteConstraints, RouteTypesById, RouteMask, RouteExtensions, RouteLazyFn, RouteAddChildrenFn, RouteAddFileChildrenFn, RouteAddFileTypesFn, ResolveOptionalParams, ResolveRequiredParams, } from './route.js';
|
|
19
19
|
export { defaultSerializeError, getLocationChangeInfo, RouterCore, componentTypes, lazyFn, SearchParamError, PathParamError, getInitialRouterState, processRouteTree, getMatchedRoutes, } from './router.js';
|
|
20
|
-
export type { ViewTransitionOptions, ExtractedBaseEntry, ExtractedStream, ExtractedPromise, ExtractedEntry, StreamState, TrailingSlashOption, Register, AnyRouter, AnyRouterWithContext, RegisteredRouter, RouterState, BuildNextOptions, RouterListener, RouterEvent, ListenerFn, RouterEvents, MatchRoutesOpts, RouterOptionsExtensions, DefaultRemountDepsFn, PreloadRouteFn, MatchRouteFn, RouterContextOptions, RouterOptions, RouterConstructorOptions, UpdateFn, ParseLocationFn, InvalidateFn, ControllablePromise, InjectedHtmlEntry, RouterErrorSerializer,
|
|
20
|
+
export type { ViewTransitionOptions, ExtractedBaseEntry, ExtractedStream, ExtractedPromise, ExtractedEntry, StreamState, TrailingSlashOption, Register, AnyRouter, AnyRouterWithContext, RegisteredRouter, RouterState, BuildNextOptions, RouterListener, RouterEvent, ListenerFn, RouterEvents, MatchRoutesOpts, RouterOptionsExtensions, DefaultRemountDepsFn, PreloadRouteFn, MatchRouteFn, RouterContextOptions, RouterOptions, RouterConstructorOptions, UpdateFn, ParseLocationFn, InvalidateFn, ControllablePromise, InjectedHtmlEntry, RouterErrorSerializer, EmitFn, LoadFn, GetMatchFn, SubscribeFn, UpdateMatchFn, CommitLocationFn, GetMatchRoutesFn, MatchRoutesFn, StartTransitionFn, LoadRouteChunkFn, ServerSrr, ClearCacheFn, CreateRouterFn, } from './router.js';
|
|
21
21
|
export type { MatchLocation, CommitLocationOptions, NavigateFn, BuildLocationFn, } from './RouterProvider.js';
|
|
22
22
|
export { retainSearchParams, stripSearchParams } from './searchMiddleware.js';
|
|
23
23
|
export { defaultParseSearch, defaultStringifySearch, parseSearchWith, stringifySearchWith, } from './searchParams.js';
|
package/dist/esm/link.d.ts
CHANGED
|
@@ -113,7 +113,7 @@ export type ToSubOptionsProps<TRouter extends AnyRouter = RegisteredRouter, TFro
|
|
|
113
113
|
hash?: true | Updater<string>;
|
|
114
114
|
state?: true | NonNullableUpdater<ParsedHistoryState, HistoryState>;
|
|
115
115
|
from?: FromPathOption<TRouter, TFrom> & {};
|
|
116
|
-
|
|
116
|
+
unsafeRelative?: 'route' | 'path';
|
|
117
117
|
};
|
|
118
118
|
export type ParamsReducerFn<in out TRouter extends AnyRouter, in out TParamVariant extends ParamVariant, in out TFrom, in out TTo> = (current: Expand<ResolveFromParams<TRouter, TParamVariant, TFrom>>) => Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>;
|
|
119
119
|
type ParamsReducer<TRouter extends AnyRouter, TParamVariant extends ParamVariant, TFrom, TTo> = Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>> | (ParamsReducerFn<TRouter, TParamVariant, TFrom, TTo> & {});
|
package/dist/esm/link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","sources":["../../src/link.ts"],"sourcesContent":["import type { HistoryState, ParsedHistoryState } from '@tanstack/history'\nimport type {\n AllParams,\n CatchAllPaths,\n CurrentPath,\n FullSearchSchema,\n FullSearchSchemaInput,\n ParentPath,\n RouteByPath,\n RouteByToPath,\n RoutePaths,\n RouteToPath,\n ToPath,\n} from './routeInfo'\nimport type {\n AnyRouter,\n RegisteredRouter,\n ViewTransitionOptions,\n} from './router'\nimport type {\n ConstrainLiteral,\n Expand,\n MakeDifferenceOptional,\n NoInfer,\n NonNullableUpdater,\n Updater,\n} from './utils'\nimport type { ParsedLocation } from './location'\n\nexport type IsRequiredParams<TParams> =\n Record<never, never> extends TParams ? never : true\n\nexport interface ParsePathParamsResult<\n in out TRequired,\n in out TOptional,\n in out TRest,\n> {\n required: TRequired\n optional: TOptional\n rest: TRest\n}\n\nexport type AnyParsePathParamsResult = ParsePathParamsResult<\n string,\n string,\n string\n>\n\nexport type ParsePathParamsBoundaryStart<T extends string> =\n T extends `${infer TLeft}{-${infer TRight}`\n ? ParsePathParamsResult<\n ParsePathParams<TLeft>['required'],\n | ParsePathParams<TLeft>['optional']\n | ParsePathParams<TRight>['required']\n | ParsePathParams<TRight>['optional'],\n ParsePathParams<TRight>['rest']\n >\n : T extends `${infer TLeft}{${infer TRight}`\n ? ParsePathParamsResult<\n | ParsePathParams<TLeft>['required']\n | ParsePathParams<TRight>['required'],\n | ParsePathParams<TLeft>['optional']\n | ParsePathParams<TRight>['optional'],\n ParsePathParams<TRight>['rest']\n >\n : never\n\nexport type ParsePathParamsSymbol<T extends string> =\n T extends `${string}$${infer TRight}`\n ? TRight extends `${string}/${string}`\n ? TRight extends `${infer TParam}/${infer TRest}`\n ? TParam extends ''\n ? ParsePathParamsResult<\n ParsePathParams<TRest>['required'],\n '_splat' | ParsePathParams<TRest>['optional'],\n ParsePathParams<TRest>['rest']\n >\n : ParsePathParamsResult<\n TParam | ParsePathParams<TRest>['required'],\n ParsePathParams<TRest>['optional'],\n ParsePathParams<TRest>['rest']\n >\n : never\n : TRight extends ''\n ? ParsePathParamsResult<never, '_splat', never>\n : ParsePathParamsResult<TRight, never, never>\n : never\n\nexport type ParsePathParamsBoundaryEnd<T extends string> =\n T extends `${infer TLeft}}${infer TRight}`\n ? ParsePathParamsResult<\n | ParsePathParams<TLeft>['required']\n | ParsePathParams<TRight>['required'],\n | ParsePathParams<TLeft>['optional']\n | ParsePathParams<TRight>['optional'],\n ParsePathParams<TRight>['rest']\n >\n : never\n\nexport type ParsePathParamsEscapeStart<T extends string> =\n T extends `${infer TLeft}[${infer TRight}`\n ? ParsePathParamsResult<\n | ParsePathParams<TLeft>['required']\n | ParsePathParams<TRight>['required'],\n | ParsePathParams<TLeft>['optional']\n | ParsePathParams<TRight>['optional'],\n ParsePathParams<TRight>['rest']\n >\n : never\n\nexport type ParsePathParamsEscapeEnd<T extends string> =\n T extends `${string}]${infer TRight}` ? ParsePathParams<TRight> : never\n\nexport type ParsePathParams<T extends string> = T extends `${string}[${string}`\n ? ParsePathParamsEscapeStart<T>\n : T extends `${string}]${string}`\n ? ParsePathParamsEscapeEnd<T>\n : T extends `${string}}${string}`\n ? ParsePathParamsBoundaryEnd<T>\n : T extends `${string}{${string}`\n ? ParsePathParamsBoundaryStart<T>\n : T extends `${string}$${string}`\n ? ParsePathParamsSymbol<T>\n : never\n\nexport type AddTrailingSlash<T> = T extends `${string}/` ? T : `${T & string}/`\n\nexport type RemoveTrailingSlashes<T> = T & `${string}/` extends never\n ? T\n : T extends `${infer R}/`\n ? R\n : T\n\nexport type AddLeadingSlash<T> = T & `/${string}` extends never\n ? `/${T & string}`\n : T\n\nexport type RemoveLeadingSlashes<T> = T & `/${string}` extends never\n ? T\n : T extends `/${infer R}`\n ? R\n : T\n\ntype JoinPath<TLeft extends string, TRight extends string> = TRight extends ''\n ? TLeft\n : TLeft extends ''\n ? TRight\n : `${RemoveTrailingSlashes<TLeft>}/${RemoveLeadingSlashes<TRight>}`\n\ntype RemoveLastSegment<\n T extends string,\n TAcc extends string = '',\n> = T extends `${infer TSegment}/${infer TRest}`\n ? TRest & `${string}/${string}` extends never\n ? TRest extends ''\n ? TAcc\n : `${TAcc}${TSegment}`\n : RemoveLastSegment<TRest, `${TAcc}${TSegment}/`>\n : TAcc\n\nexport type ResolveCurrentPath<\n TFrom extends string,\n TTo extends string,\n> = TTo extends '.'\n ? TFrom\n : TTo extends './'\n ? AddTrailingSlash<TFrom>\n : TTo & `./${string}` extends never\n ? never\n : TTo extends `./${infer TRest}`\n ? AddLeadingSlash<JoinPath<TFrom, TRest>>\n : never\n\nexport type ResolveParentPath<\n TFrom extends string,\n TTo extends string,\n> = TTo extends '../' | '..'\n ? TFrom extends '' | '/'\n ? never\n : AddLeadingSlash<RemoveLastSegment<TFrom>>\n : TTo & `../${string}` extends never\n ? AddLeadingSlash<JoinPath<TFrom, TTo>>\n : TFrom extends '' | '/'\n ? never\n : TTo extends `../${infer ToRest}`\n ? ResolveParentPath<RemoveLastSegment<TFrom>, ToRest>\n : AddLeadingSlash<JoinPath<TFrom, TTo>>\n\nexport type ResolveRelativePath<TFrom, TTo = '.'> = string extends TFrom\n ? TTo\n : string extends TTo\n ? TFrom\n : undefined extends TTo\n ? TFrom\n : TTo extends string\n ? TFrom extends string\n ? TTo extends `/${string}`\n ? TTo\n : TTo extends `..${string}`\n ? ResolveParentPath<TFrom, TTo>\n : TTo extends `.${string}`\n ? ResolveCurrentPath<TFrom, TTo>\n : AddLeadingSlash<JoinPath<TFrom, TTo>>\n : never\n : never\n\nexport type FindDescendantToPaths<\n TRouter extends AnyRouter,\n TPrefix extends string,\n> = `${TPrefix}/${string}` & RouteToPath<TRouter>\n\nexport type InferDescendantToPaths<\n TRouter extends AnyRouter,\n TPrefix extends string,\n TPaths = FindDescendantToPaths<TRouter, TPrefix>,\n> = TPaths extends `${TPrefix}/`\n ? never\n : TPaths extends `${TPrefix}/${infer TRest}`\n ? TRest\n : never\n\nexport type RelativeToPath<\n TRouter extends AnyRouter,\n TTo extends string,\n TResolvedPath extends string,\n> =\n | (TResolvedPath & RouteToPath<TRouter> extends never\n ? never\n : ToPath<TRouter, TTo>)\n | `${RemoveTrailingSlashes<TTo>}/${InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TResolvedPath>>}`\n\nexport type RelativeToParentPath<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string,\n TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>,\n> =\n | RelativeToPath<TRouter, TTo, TResolvedPath>\n | (TTo extends `${string}..` | `${string}../`\n ? TResolvedPath extends '/' | ''\n ? never\n : FindDescendantToPaths<\n TRouter,\n RemoveTrailingSlashes<TResolvedPath>\n > extends never\n ? never\n : `${RemoveTrailingSlashes<TTo>}/${ParentPath<TRouter>}`\n : never)\n\nexport type RelativeToCurrentPath<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string,\n TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>,\n> = RelativeToPath<TRouter, TTo, TResolvedPath> | CurrentPath<TRouter>\n\nexport type AbsoluteToPath<TRouter extends AnyRouter, TFrom extends string> =\n | (string extends TFrom\n ? CurrentPath<TRouter>\n : TFrom extends `/`\n ? never\n : CurrentPath<TRouter>)\n | (string extends TFrom\n ? ParentPath<TRouter>\n : TFrom extends `/`\n ? never\n : ParentPath<TRouter>)\n | RouteToPath<TRouter>\n | (TFrom extends '/'\n ? never\n : string extends TFrom\n ? never\n : InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TFrom>>)\n\nexport type RelativeToPathAutoComplete<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string,\n> = string extends TTo\n ? string\n : string extends TFrom\n ? AbsoluteToPath<TRouter, TFrom>\n : TTo & `..${string}` extends never\n ? TTo & `.${string}` extends never\n ? AbsoluteToPath<TRouter, TFrom>\n : RelativeToCurrentPath<TRouter, TFrom, TTo>\n : RelativeToParentPath<TRouter, TFrom, TTo>\n\nexport type NavigateOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & NavigateOptionProps\n\n/**\n * The NavigateOptions type is used to describe the options that can be used when describing a navigation action in TanStack Router.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType)\n */\nexport interface NavigateOptionProps {\n /**\n * If set to `true`, the router will scroll the element with an id matching the hash into view with default `ScrollIntoViewOptions`.\n * If set to `false`, the router will not scroll the element with an id matching the hash into view.\n * If set to `ScrollIntoViewOptions`, the router will scroll the element with an id matching the hash into view with the provided options.\n * @default true\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#hashscrollintoview)\n * @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView)\n */\n hashScrollIntoView?: boolean | ScrollIntoViewOptions\n /**\n * `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.\n * @default false\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#replace)\n */\n replace?: boolean\n /**\n * Defaults to `true` so that the scroll position will be reset to 0,0 after the location is committed to the browser history.\n * If `false`, the scroll position will not be reset to 0,0 after the location is committed to history.\n * @default true\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#resetscroll)\n */\n resetScroll?: boolean\n /** @deprecated All navigations now use startTransition under the hood */\n startTransition?: boolean\n /**\n * If set to `true`, the router will wrap the resulting navigation in a `document.startViewTransition()` call.\n * If `ViewTransitionOptions`, route navigations will be called using `document.startViewTransition({update, types})`\n * where `types` will be the strings array passed with `ViewTransitionOptions[\"types\"]`.\n * If the browser does not support viewTransition types, the navigation will fall back to normal `document.startTransition()`, same as if `true` was passed.\n *\n * If the browser does not support this api, this option will be ignored.\n * @default false\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#viewtransition)\n * @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition)\n * @see [Google](https://developer.chrome.com/docs/web-platform/view-transitions/same-document#view-transition-types)\n */\n viewTransition?: boolean | ViewTransitionOptions\n /**\n * If `true`, navigation will ignore any blockers that might prevent it.\n * @default false\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#ignoreblocker)\n */\n ignoreBlocker?: boolean\n /**\n * If `true`, navigation to a route inside of router will trigger a full page load instead of the traditional SPA navigation.\n * @default false\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#reloaddocument)\n */\n reloadDocument?: boolean\n /**\n * This can be used instead of `to` to navigate to a fully built href, e.g. pointing to an external target.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#href)\n */\n href?: string\n}\n\nexport type ToOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = ToSubOptions<TRouter, TFrom, TTo> & MaskOptions<TRouter, TMaskFrom, TMaskTo>\n\nexport interface MaskOptions<\n in out TRouter extends AnyRouter,\n in out TMaskFrom extends string,\n in out TMaskTo extends string,\n> {\n _fromLocation?: ParsedLocation\n mask?: ToMaskOptions<TRouter, TMaskFrom, TMaskTo>\n}\n\nexport type ToMaskOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TMaskFrom extends string = string,\n TMaskTo extends string = '.',\n> = ToSubOptions<TRouter, TMaskFrom, TMaskTo> & {\n unmaskOnReload?: boolean\n}\n\nexport type ToSubOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n> = ToSubOptionsProps<TRouter, TFrom, TTo> &\n SearchParamOptions<TRouter, TFrom, TTo> &\n PathParamOptions<TRouter, TFrom, TTo>\n\nexport interface RequiredToOptions<\n in out TRouter extends AnyRouter,\n in out TFrom extends string,\n in out TTo extends string | undefined,\n> {\n to: ToPathOption<TRouter, TFrom, TTo> & {}\n}\n\nexport interface OptionalToOptions<\n in out TRouter extends AnyRouter,\n in out TFrom extends string,\n in out TTo extends string | undefined,\n> {\n to?: ToPathOption<TRouter, TFrom, TTo> & {}\n}\n\nexport type MakeToRequired<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string | undefined,\n> = string extends TFrom\n ? string extends TTo\n ? OptionalToOptions<TRouter, TFrom, TTo>\n : TTo & CatchAllPaths<TRouter> extends never\n ? RequiredToOptions<TRouter, TFrom, TTo>\n : OptionalToOptions<TRouter, TFrom, TTo>\n : OptionalToOptions<TRouter, TFrom, TTo>\n\nexport type ToSubOptionsProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string | undefined = '.',\n> = MakeToRequired<TRouter, TFrom, TTo> & {\n hash?: true | Updater<string>\n state?: true | NonNullableUpdater<ParsedHistoryState, HistoryState>\n from?: FromPathOption<TRouter, TFrom> & {}\n relative?: 'route' | 'path'\n}\n\nexport type ParamsReducerFn<\n in out TRouter extends AnyRouter,\n in out TParamVariant extends ParamVariant,\n in out TFrom,\n in out TTo,\n> = (\n current: Expand<ResolveFromParams<TRouter, TParamVariant, TFrom>>,\n) => Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>\n\ntype ParamsReducer<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n | Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>\n | (ParamsReducerFn<TRouter, TParamVariant, TFrom, TTo> & {})\n\ntype ParamVariant = 'PATH' | 'SEARCH'\n\nexport type ResolveRoute<\n TRouter extends AnyRouter,\n TFrom,\n TTo,\n TPath = ResolveRelativePath<TFrom, TTo>,\n> = TPath extends string\n ? TFrom extends TPath\n ? RouteByPath<TRouter['routeTree'], TPath>\n : RouteByToPath<TRouter, TPath>\n : never\n\ntype ResolveFromParamType<TParamVariant extends ParamVariant> =\n TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema'\n\ntype ResolveFromAllParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n> = TParamVariant extends 'PATH'\n ? AllParams<TRouter['routeTree']>\n : FullSearchSchema<TRouter['routeTree']>\n\ntype ResolveFromParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n> = string extends TFrom\n ? ResolveFromAllParams<TRouter, TParamVariant>\n : RouteByPath<\n TRouter['routeTree'],\n TFrom\n >['types'][ResolveFromParamType<TParamVariant>]\n\ntype ResolveToParamType<TParamVariant extends ParamVariant> =\n TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchemaInput'\n\ntype ResolveAllToParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n> = TParamVariant extends 'PATH'\n ? AllParams<TRouter['routeTree']>\n : FullSearchSchemaInput<TRouter['routeTree']>\n\nexport type ResolveToParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n ResolveRelativePath<TFrom, TTo> extends infer TPath\n ? undefined extends TPath\n ? never\n : string extends TPath\n ? ResolveAllToParams<TRouter, TParamVariant>\n : TPath extends CatchAllPaths<TRouter>\n ? ResolveAllToParams<TRouter, TParamVariant>\n : ResolveRoute<\n TRouter,\n TFrom,\n TTo\n >['types'][ResolveToParamType<TParamVariant>]\n : never\n\ntype ResolveRelativeToParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n TToParams = ResolveToParams<TRouter, TParamVariant, TFrom, TTo>,\n> = TParamVariant extends 'SEARCH'\n ? TToParams\n : string extends TFrom\n ? TToParams\n : MakeDifferenceOptional<\n ResolveFromParams<TRouter, TParamVariant, TFrom>,\n TToParams\n >\n\nexport interface MakeOptionalSearchParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n search?: true | (ParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {})\n}\n\nexport interface MakeOptionalPathParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n params?: true | (ParamsReducer<TRouter, 'PATH', TFrom, TTo> & {})\n}\n\ntype MakeRequiredParamsReducer<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n | (string extends TFrom\n ? never\n : ResolveFromParams<\n TRouter,\n TParamVariant,\n TFrom\n > extends ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>\n ? true\n : never)\n | (ParamsReducer<TRouter, TParamVariant, TFrom, TTo> & {})\n\nexport interface MakeRequiredPathParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n params: MakeRequiredParamsReducer<TRouter, 'PATH', TFrom, TTo> & {}\n}\n\nexport interface MakeRequiredSearchParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n search: MakeRequiredParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {}\n}\n\nexport type IsRequired<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n ResolveRelativePath<TFrom, TTo> extends infer TPath\n ? undefined extends TPath\n ? never\n : TPath extends CatchAllPaths<TRouter>\n ? never\n : IsRequiredParams<\n ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>\n >\n : never\n\nexport type SearchParamOptions<TRouter extends AnyRouter, TFrom, TTo> =\n IsRequired<TRouter, 'SEARCH', TFrom, TTo> extends never\n ? MakeOptionalSearchParams<TRouter, TFrom, TTo>\n : MakeRequiredSearchParams<TRouter, TFrom, TTo>\n\nexport type PathParamOptions<TRouter extends AnyRouter, TFrom, TTo> =\n IsRequired<TRouter, 'PATH', TFrom, TTo> extends never\n ? MakeOptionalPathParams<TRouter, TFrom, TTo>\n : MakeRequiredPathParams<TRouter, TFrom, TTo>\n\nexport type ToPathOption<\n TRouter extends AnyRouter = AnyRouter,\n TFrom extends string = string,\n TTo extends string | undefined = string,\n> = ConstrainLiteral<\n TTo,\n RelativeToPathAutoComplete<\n TRouter,\n NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',\n NoInfer<TTo> & string\n >\n>\n\nexport type FromPathOption<TRouter extends AnyRouter, TFrom> = ConstrainLiteral<\n TFrom,\n RoutePaths<TRouter['routeTree']>\n>\n\n/**\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/navigation#active-options)\n */\nexport interface ActiveOptions {\n /**\n * If true, the link will be active if the current route matches the `to` route path exactly (no children routes)\n * @default false\n */\n exact?: boolean\n /**\n * If true, the link will only be active if the current URL hash matches the `hash` prop\n * @default false\n */\n includeHash?: boolean\n /**\n * If true, the link will only be active if the current URL search params inclusively match the `search` prop\n * @default true\n */\n includeSearch?: boolean\n /**\n * This modifies the `includeSearch` behavior.\n * If true, properties in `search` that are explicitly `undefined` must NOT be present in the current URL search params for the link to be active.\n * @default false\n */\n explicitUndefined?: boolean\n}\n\nexport interface LinkOptionsProps {\n /**\n * The standard anchor tag target attribute\n */\n target?: HTMLAnchorElement['target']\n /**\n * Configurable options to determine if the link should be considered active or not\n * @default {exact:true,includeHash:true}\n */\n activeOptions?: ActiveOptions\n /**\n * The preloading strategy for this link\n * - `false` - No preloading\n * - `'intent'` - Preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.\n * - `'viewport'` - Preload the linked route when it enters the viewport\n */\n preload?: false | 'intent' | 'viewport' | 'render'\n /**\n * When a preload strategy is set, this delays the preload by this many milliseconds.\n * If the user exits the link before this delay, the preload will be cancelled.\n */\n preloadDelay?: number\n /**\n * Control whether the link should be disabled or not\n * If set to `true`, the link will be rendered without an `href` attribute\n * @default false\n */\n disabled?: boolean\n /**\n * When the preload strategy is set to `intent`, this controls the proximity of the link to the cursor before it is preloaded.\n * If the user exits this proximity before this delay, the preload will be cancelled.\n */\n preloadIntentProximity?: number\n}\n\nexport type LinkOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & LinkOptionsProps\n\nexport type LinkCurrentTargetElement = {\n preloadTimeout?: null | ReturnType<typeof setTimeout>\n}\n\nexport const preloadWarning = 'Error preloading route! ☝️'\n"],"names":[],"mappings":"AAqrBO,MAAM,iBAAiB;"}
|
|
1
|
+
{"version":3,"file":"link.js","sources":["../../src/link.ts"],"sourcesContent":["import type { HistoryState, ParsedHistoryState } from '@tanstack/history'\nimport type {\n AllParams,\n CatchAllPaths,\n CurrentPath,\n FullSearchSchema,\n FullSearchSchemaInput,\n ParentPath,\n RouteByPath,\n RouteByToPath,\n RoutePaths,\n RouteToPath,\n ToPath,\n} from './routeInfo'\nimport type {\n AnyRouter,\n RegisteredRouter,\n ViewTransitionOptions,\n} from './router'\nimport type {\n ConstrainLiteral,\n Expand,\n MakeDifferenceOptional,\n NoInfer,\n NonNullableUpdater,\n Updater,\n} from './utils'\nimport type { ParsedLocation } from './location'\n\nexport type IsRequiredParams<TParams> =\n Record<never, never> extends TParams ? never : true\n\nexport interface ParsePathParamsResult<\n in out TRequired,\n in out TOptional,\n in out TRest,\n> {\n required: TRequired\n optional: TOptional\n rest: TRest\n}\n\nexport type AnyParsePathParamsResult = ParsePathParamsResult<\n string,\n string,\n string\n>\n\nexport type ParsePathParamsBoundaryStart<T extends string> =\n T extends `${infer TLeft}{-${infer TRight}`\n ? ParsePathParamsResult<\n ParsePathParams<TLeft>['required'],\n | ParsePathParams<TLeft>['optional']\n | ParsePathParams<TRight>['required']\n | ParsePathParams<TRight>['optional'],\n ParsePathParams<TRight>['rest']\n >\n : T extends `${infer TLeft}{${infer TRight}`\n ? ParsePathParamsResult<\n | ParsePathParams<TLeft>['required']\n | ParsePathParams<TRight>['required'],\n | ParsePathParams<TLeft>['optional']\n | ParsePathParams<TRight>['optional'],\n ParsePathParams<TRight>['rest']\n >\n : never\n\nexport type ParsePathParamsSymbol<T extends string> =\n T extends `${string}$${infer TRight}`\n ? TRight extends `${string}/${string}`\n ? TRight extends `${infer TParam}/${infer TRest}`\n ? TParam extends ''\n ? ParsePathParamsResult<\n ParsePathParams<TRest>['required'],\n '_splat' | ParsePathParams<TRest>['optional'],\n ParsePathParams<TRest>['rest']\n >\n : ParsePathParamsResult<\n TParam | ParsePathParams<TRest>['required'],\n ParsePathParams<TRest>['optional'],\n ParsePathParams<TRest>['rest']\n >\n : never\n : TRight extends ''\n ? ParsePathParamsResult<never, '_splat', never>\n : ParsePathParamsResult<TRight, never, never>\n : never\n\nexport type ParsePathParamsBoundaryEnd<T extends string> =\n T extends `${infer TLeft}}${infer TRight}`\n ? ParsePathParamsResult<\n | ParsePathParams<TLeft>['required']\n | ParsePathParams<TRight>['required'],\n | ParsePathParams<TLeft>['optional']\n | ParsePathParams<TRight>['optional'],\n ParsePathParams<TRight>['rest']\n >\n : never\n\nexport type ParsePathParamsEscapeStart<T extends string> =\n T extends `${infer TLeft}[${infer TRight}`\n ? ParsePathParamsResult<\n | ParsePathParams<TLeft>['required']\n | ParsePathParams<TRight>['required'],\n | ParsePathParams<TLeft>['optional']\n | ParsePathParams<TRight>['optional'],\n ParsePathParams<TRight>['rest']\n >\n : never\n\nexport type ParsePathParamsEscapeEnd<T extends string> =\n T extends `${string}]${infer TRight}` ? ParsePathParams<TRight> : never\n\nexport type ParsePathParams<T extends string> = T extends `${string}[${string}`\n ? ParsePathParamsEscapeStart<T>\n : T extends `${string}]${string}`\n ? ParsePathParamsEscapeEnd<T>\n : T extends `${string}}${string}`\n ? ParsePathParamsBoundaryEnd<T>\n : T extends `${string}{${string}`\n ? ParsePathParamsBoundaryStart<T>\n : T extends `${string}$${string}`\n ? ParsePathParamsSymbol<T>\n : never\n\nexport type AddTrailingSlash<T> = T extends `${string}/` ? T : `${T & string}/`\n\nexport type RemoveTrailingSlashes<T> = T & `${string}/` extends never\n ? T\n : T extends `${infer R}/`\n ? R\n : T\n\nexport type AddLeadingSlash<T> = T & `/${string}` extends never\n ? `/${T & string}`\n : T\n\nexport type RemoveLeadingSlashes<T> = T & `/${string}` extends never\n ? T\n : T extends `/${infer R}`\n ? R\n : T\n\ntype JoinPath<TLeft extends string, TRight extends string> = TRight extends ''\n ? TLeft\n : TLeft extends ''\n ? TRight\n : `${RemoveTrailingSlashes<TLeft>}/${RemoveLeadingSlashes<TRight>}`\n\ntype RemoveLastSegment<\n T extends string,\n TAcc extends string = '',\n> = T extends `${infer TSegment}/${infer TRest}`\n ? TRest & `${string}/${string}` extends never\n ? TRest extends ''\n ? TAcc\n : `${TAcc}${TSegment}`\n : RemoveLastSegment<TRest, `${TAcc}${TSegment}/`>\n : TAcc\n\nexport type ResolveCurrentPath<\n TFrom extends string,\n TTo extends string,\n> = TTo extends '.'\n ? TFrom\n : TTo extends './'\n ? AddTrailingSlash<TFrom>\n : TTo & `./${string}` extends never\n ? never\n : TTo extends `./${infer TRest}`\n ? AddLeadingSlash<JoinPath<TFrom, TRest>>\n : never\n\nexport type ResolveParentPath<\n TFrom extends string,\n TTo extends string,\n> = TTo extends '../' | '..'\n ? TFrom extends '' | '/'\n ? never\n : AddLeadingSlash<RemoveLastSegment<TFrom>>\n : TTo & `../${string}` extends never\n ? AddLeadingSlash<JoinPath<TFrom, TTo>>\n : TFrom extends '' | '/'\n ? never\n : TTo extends `../${infer ToRest}`\n ? ResolveParentPath<RemoveLastSegment<TFrom>, ToRest>\n : AddLeadingSlash<JoinPath<TFrom, TTo>>\n\nexport type ResolveRelativePath<TFrom, TTo = '.'> = string extends TFrom\n ? TTo\n : string extends TTo\n ? TFrom\n : undefined extends TTo\n ? TFrom\n : TTo extends string\n ? TFrom extends string\n ? TTo extends `/${string}`\n ? TTo\n : TTo extends `..${string}`\n ? ResolveParentPath<TFrom, TTo>\n : TTo extends `.${string}`\n ? ResolveCurrentPath<TFrom, TTo>\n : AddLeadingSlash<JoinPath<TFrom, TTo>>\n : never\n : never\n\nexport type FindDescendantToPaths<\n TRouter extends AnyRouter,\n TPrefix extends string,\n> = `${TPrefix}/${string}` & RouteToPath<TRouter>\n\nexport type InferDescendantToPaths<\n TRouter extends AnyRouter,\n TPrefix extends string,\n TPaths = FindDescendantToPaths<TRouter, TPrefix>,\n> = TPaths extends `${TPrefix}/`\n ? never\n : TPaths extends `${TPrefix}/${infer TRest}`\n ? TRest\n : never\n\nexport type RelativeToPath<\n TRouter extends AnyRouter,\n TTo extends string,\n TResolvedPath extends string,\n> =\n | (TResolvedPath & RouteToPath<TRouter> extends never\n ? never\n : ToPath<TRouter, TTo>)\n | `${RemoveTrailingSlashes<TTo>}/${InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TResolvedPath>>}`\n\nexport type RelativeToParentPath<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string,\n TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>,\n> =\n | RelativeToPath<TRouter, TTo, TResolvedPath>\n | (TTo extends `${string}..` | `${string}../`\n ? TResolvedPath extends '/' | ''\n ? never\n : FindDescendantToPaths<\n TRouter,\n RemoveTrailingSlashes<TResolvedPath>\n > extends never\n ? never\n : `${RemoveTrailingSlashes<TTo>}/${ParentPath<TRouter>}`\n : never)\n\nexport type RelativeToCurrentPath<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string,\n TResolvedPath extends string = ResolveRelativePath<TFrom, TTo>,\n> = RelativeToPath<TRouter, TTo, TResolvedPath> | CurrentPath<TRouter>\n\nexport type AbsoluteToPath<TRouter extends AnyRouter, TFrom extends string> =\n | (string extends TFrom\n ? CurrentPath<TRouter>\n : TFrom extends `/`\n ? never\n : CurrentPath<TRouter>)\n | (string extends TFrom\n ? ParentPath<TRouter>\n : TFrom extends `/`\n ? never\n : ParentPath<TRouter>)\n | RouteToPath<TRouter>\n | (TFrom extends '/'\n ? never\n : string extends TFrom\n ? never\n : InferDescendantToPaths<TRouter, RemoveTrailingSlashes<TFrom>>)\n\nexport type RelativeToPathAutoComplete<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string,\n> = string extends TTo\n ? string\n : string extends TFrom\n ? AbsoluteToPath<TRouter, TFrom>\n : TTo & `..${string}` extends never\n ? TTo & `.${string}` extends never\n ? AbsoluteToPath<TRouter, TFrom>\n : RelativeToCurrentPath<TRouter, TFrom, TTo>\n : RelativeToParentPath<TRouter, TFrom, TTo>\n\nexport type NavigateOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & NavigateOptionProps\n\n/**\n * The NavigateOptions type is used to describe the options that can be used when describing a navigation action in TanStack Router.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType)\n */\nexport interface NavigateOptionProps {\n /**\n * If set to `true`, the router will scroll the element with an id matching the hash into view with default `ScrollIntoViewOptions`.\n * If set to `false`, the router will not scroll the element with an id matching the hash into view.\n * If set to `ScrollIntoViewOptions`, the router will scroll the element with an id matching the hash into view with the provided options.\n * @default true\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#hashscrollintoview)\n * @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView)\n */\n hashScrollIntoView?: boolean | ScrollIntoViewOptions\n /**\n * `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.\n * @default false\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#replace)\n */\n replace?: boolean\n /**\n * Defaults to `true` so that the scroll position will be reset to 0,0 after the location is committed to the browser history.\n * If `false`, the scroll position will not be reset to 0,0 after the location is committed to history.\n * @default true\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#resetscroll)\n */\n resetScroll?: boolean\n /** @deprecated All navigations now use startTransition under the hood */\n startTransition?: boolean\n /**\n * If set to `true`, the router will wrap the resulting navigation in a `document.startViewTransition()` call.\n * If `ViewTransitionOptions`, route navigations will be called using `document.startViewTransition({update, types})`\n * where `types` will be the strings array passed with `ViewTransitionOptions[\"types\"]`.\n * If the browser does not support viewTransition types, the navigation will fall back to normal `document.startTransition()`, same as if `true` was passed.\n *\n * If the browser does not support this api, this option will be ignored.\n * @default false\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#viewtransition)\n * @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition)\n * @see [Google](https://developer.chrome.com/docs/web-platform/view-transitions/same-document#view-transition-types)\n */\n viewTransition?: boolean | ViewTransitionOptions\n /**\n * If `true`, navigation will ignore any blockers that might prevent it.\n * @default false\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#ignoreblocker)\n */\n ignoreBlocker?: boolean\n /**\n * If `true`, navigation to a route inside of router will trigger a full page load instead of the traditional SPA navigation.\n * @default false\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#reloaddocument)\n */\n reloadDocument?: boolean\n /**\n * This can be used instead of `to` to navigate to a fully built href, e.g. pointing to an external target.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#href)\n */\n href?: string\n}\n\nexport type ToOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = ToSubOptions<TRouter, TFrom, TTo> & MaskOptions<TRouter, TMaskFrom, TMaskTo>\n\nexport interface MaskOptions<\n in out TRouter extends AnyRouter,\n in out TMaskFrom extends string,\n in out TMaskTo extends string,\n> {\n _fromLocation?: ParsedLocation\n mask?: ToMaskOptions<TRouter, TMaskFrom, TMaskTo>\n}\n\nexport type ToMaskOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TMaskFrom extends string = string,\n TMaskTo extends string = '.',\n> = ToSubOptions<TRouter, TMaskFrom, TMaskTo> & {\n unmaskOnReload?: boolean\n}\n\nexport type ToSubOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n> = ToSubOptionsProps<TRouter, TFrom, TTo> &\n SearchParamOptions<TRouter, TFrom, TTo> &\n PathParamOptions<TRouter, TFrom, TTo>\n\nexport interface RequiredToOptions<\n in out TRouter extends AnyRouter,\n in out TFrom extends string,\n in out TTo extends string | undefined,\n> {\n to: ToPathOption<TRouter, TFrom, TTo> & {}\n}\n\nexport interface OptionalToOptions<\n in out TRouter extends AnyRouter,\n in out TFrom extends string,\n in out TTo extends string | undefined,\n> {\n to?: ToPathOption<TRouter, TFrom, TTo> & {}\n}\n\nexport type MakeToRequired<\n TRouter extends AnyRouter,\n TFrom extends string,\n TTo extends string | undefined,\n> = string extends TFrom\n ? string extends TTo\n ? OptionalToOptions<TRouter, TFrom, TTo>\n : TTo & CatchAllPaths<TRouter> extends never\n ? RequiredToOptions<TRouter, TFrom, TTo>\n : OptionalToOptions<TRouter, TFrom, TTo>\n : OptionalToOptions<TRouter, TFrom, TTo>\n\nexport type ToSubOptionsProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string | undefined = '.',\n> = MakeToRequired<TRouter, TFrom, TTo> & {\n hash?: true | Updater<string>\n state?: true | NonNullableUpdater<ParsedHistoryState, HistoryState>\n from?: FromPathOption<TRouter, TFrom> & {}\n unsafeRelative?: 'route' | 'path'\n}\n\nexport type ParamsReducerFn<\n in out TRouter extends AnyRouter,\n in out TParamVariant extends ParamVariant,\n in out TFrom,\n in out TTo,\n> = (\n current: Expand<ResolveFromParams<TRouter, TParamVariant, TFrom>>,\n) => Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>\n\ntype ParamsReducer<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n | Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>\n | (ParamsReducerFn<TRouter, TParamVariant, TFrom, TTo> & {})\n\ntype ParamVariant = 'PATH' | 'SEARCH'\n\nexport type ResolveRoute<\n TRouter extends AnyRouter,\n TFrom,\n TTo,\n TPath = ResolveRelativePath<TFrom, TTo>,\n> = TPath extends string\n ? TFrom extends TPath\n ? RouteByPath<TRouter['routeTree'], TPath>\n : RouteByToPath<TRouter, TPath>\n : never\n\ntype ResolveFromParamType<TParamVariant extends ParamVariant> =\n TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema'\n\ntype ResolveFromAllParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n> = TParamVariant extends 'PATH'\n ? AllParams<TRouter['routeTree']>\n : FullSearchSchema<TRouter['routeTree']>\n\ntype ResolveFromParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n> = string extends TFrom\n ? ResolveFromAllParams<TRouter, TParamVariant>\n : RouteByPath<\n TRouter['routeTree'],\n TFrom\n >['types'][ResolveFromParamType<TParamVariant>]\n\ntype ResolveToParamType<TParamVariant extends ParamVariant> =\n TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchemaInput'\n\ntype ResolveAllToParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n> = TParamVariant extends 'PATH'\n ? AllParams<TRouter['routeTree']>\n : FullSearchSchemaInput<TRouter['routeTree']>\n\nexport type ResolveToParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n ResolveRelativePath<TFrom, TTo> extends infer TPath\n ? undefined extends TPath\n ? never\n : string extends TPath\n ? ResolveAllToParams<TRouter, TParamVariant>\n : TPath extends CatchAllPaths<TRouter>\n ? ResolveAllToParams<TRouter, TParamVariant>\n : ResolveRoute<\n TRouter,\n TFrom,\n TTo\n >['types'][ResolveToParamType<TParamVariant>]\n : never\n\ntype ResolveRelativeToParams<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n TToParams = ResolveToParams<TRouter, TParamVariant, TFrom, TTo>,\n> = TParamVariant extends 'SEARCH'\n ? TToParams\n : string extends TFrom\n ? TToParams\n : MakeDifferenceOptional<\n ResolveFromParams<TRouter, TParamVariant, TFrom>,\n TToParams\n >\n\nexport interface MakeOptionalSearchParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n search?: true | (ParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {})\n}\n\nexport interface MakeOptionalPathParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n params?: true | (ParamsReducer<TRouter, 'PATH', TFrom, TTo> & {})\n}\n\ntype MakeRequiredParamsReducer<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n | (string extends TFrom\n ? never\n : ResolveFromParams<\n TRouter,\n TParamVariant,\n TFrom\n > extends ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>\n ? true\n : never)\n | (ParamsReducer<TRouter, TParamVariant, TFrom, TTo> & {})\n\nexport interface MakeRequiredPathParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n params: MakeRequiredParamsReducer<TRouter, 'PATH', TFrom, TTo> & {}\n}\n\nexport interface MakeRequiredSearchParams<\n in out TRouter extends AnyRouter,\n in out TFrom,\n in out TTo,\n> {\n search: MakeRequiredParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {}\n}\n\nexport type IsRequired<\n TRouter extends AnyRouter,\n TParamVariant extends ParamVariant,\n TFrom,\n TTo,\n> =\n ResolveRelativePath<TFrom, TTo> extends infer TPath\n ? undefined extends TPath\n ? never\n : TPath extends CatchAllPaths<TRouter>\n ? never\n : IsRequiredParams<\n ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>\n >\n : never\n\nexport type SearchParamOptions<TRouter extends AnyRouter, TFrom, TTo> =\n IsRequired<TRouter, 'SEARCH', TFrom, TTo> extends never\n ? MakeOptionalSearchParams<TRouter, TFrom, TTo>\n : MakeRequiredSearchParams<TRouter, TFrom, TTo>\n\nexport type PathParamOptions<TRouter extends AnyRouter, TFrom, TTo> =\n IsRequired<TRouter, 'PATH', TFrom, TTo> extends never\n ? MakeOptionalPathParams<TRouter, TFrom, TTo>\n : MakeRequiredPathParams<TRouter, TFrom, TTo>\n\nexport type ToPathOption<\n TRouter extends AnyRouter = AnyRouter,\n TFrom extends string = string,\n TTo extends string | undefined = string,\n> = ConstrainLiteral<\n TTo,\n RelativeToPathAutoComplete<\n TRouter,\n NoInfer<TFrom> extends string ? NoInfer<TFrom> : '',\n NoInfer<TTo> & string\n >\n>\n\nexport type FromPathOption<TRouter extends AnyRouter, TFrom> = ConstrainLiteral<\n TFrom,\n RoutePaths<TRouter['routeTree']>\n>\n\n/**\n * @link [Guide](https://tanstack.com/router/latest/docs/framework/react/guide/navigation#active-options)\n */\nexport interface ActiveOptions {\n /**\n * If true, the link will be active if the current route matches the `to` route path exactly (no children routes)\n * @default false\n */\n exact?: boolean\n /**\n * If true, the link will only be active if the current URL hash matches the `hash` prop\n * @default false\n */\n includeHash?: boolean\n /**\n * If true, the link will only be active if the current URL search params inclusively match the `search` prop\n * @default true\n */\n includeSearch?: boolean\n /**\n * This modifies the `includeSearch` behavior.\n * If true, properties in `search` that are explicitly `undefined` must NOT be present in the current URL search params for the link to be active.\n * @default false\n */\n explicitUndefined?: boolean\n}\n\nexport interface LinkOptionsProps {\n /**\n * The standard anchor tag target attribute\n */\n target?: HTMLAnchorElement['target']\n /**\n * Configurable options to determine if the link should be considered active or not\n * @default {exact:true,includeHash:true}\n */\n activeOptions?: ActiveOptions\n /**\n * The preloading strategy for this link\n * - `false` - No preloading\n * - `'intent'` - Preload the linked route on hover and cache it for this many milliseconds in hopes that the user will eventually navigate there.\n * - `'viewport'` - Preload the linked route when it enters the viewport\n */\n preload?: false | 'intent' | 'viewport' | 'render'\n /**\n * When a preload strategy is set, this delays the preload by this many milliseconds.\n * If the user exits the link before this delay, the preload will be cancelled.\n */\n preloadDelay?: number\n /**\n * Control whether the link should be disabled or not\n * If set to `true`, the link will be rendered without an `href` attribute\n * @default false\n */\n disabled?: boolean\n /**\n * When the preload strategy is set to `intent`, this controls the proximity of the link to the cursor before it is preloaded.\n * If the user exits this proximity before this delay, the preload will be cancelled.\n */\n preloadIntentProximity?: number\n}\n\nexport type LinkOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = '.',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & LinkOptionsProps\n\nexport type LinkCurrentTargetElement = {\n preloadTimeout?: null | ReturnType<typeof setTimeout>\n}\n\nexport const preloadWarning = 'Error preloading route! ☝️'\n"],"names":[],"mappings":"AAqrBO,MAAM,iBAAiB;"}
|
package/dist/esm/redirect.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
function redirect(opts) {
|
|
2
2
|
opts.statusCode = opts.statusCode || opts.code || 307;
|
|
3
|
+
if (!opts.reloadDocument) {
|
|
4
|
+
try {
|
|
5
|
+
new URL(`${opts.href}`);
|
|
6
|
+
opts.reloadDocument = true;
|
|
7
|
+
} catch {
|
|
8
|
+
}
|
|
9
|
+
}
|
|
3
10
|
const headers = new Headers(opts.headers || {});
|
|
4
11
|
const response = new Response(null, {
|
|
5
12
|
status: opts.statusCode,
|
package/dist/esm/redirect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect.js","sources":["../../src/redirect.ts"],"sourcesContent":["import type { NavigateOptions } from './link'\nimport type { AnyRouter, RegisteredRouter } from './router'\n\nexport type AnyRedirect = Redirect<any, any, any, any, any>\n\n/**\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type Redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = Response & {\n options: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n redirectHandled?: boolean\n}\n\nexport type RedirectOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = {\n href?: string\n /**\n * @deprecated Use `statusCode` instead\n **/\n code?: number\n /**\n * The HTTP status code to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#statuscode-property)\n */\n statusCode?: number\n /**\n * If provided, will throw the redirect object instead of returning it. This can be useful in places where `throwing` in a function might cause it to have a return type of `never`. In that case, you can use `redirect({ throw: true })` to throw the redirect object instead of returning it.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#throw-property)\n */\n throw?: any\n /**\n * The HTTP headers to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#headers-property)\n */\n headers?: HeadersInit\n} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type ResolvedRedirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string = '',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport function redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = '.',\n const TFrom extends string = string,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n opts: RedirectOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> {\n opts.statusCode = opts.statusCode || opts.code || 307\n const headers = new Headers(opts.headers || {})\n\n const response = new Response(null, {\n status: opts.statusCode,\n headers,\n })\n\n ;(response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>).options =\n opts\n\n if (opts.throw) {\n throw response\n }\n\n return response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n}\n\nexport function isRedirect(obj: any): obj is AnyRedirect {\n return obj instanceof Response && !!(obj as any).options\n}\n\nexport function isResolvedRedirect(\n obj: any,\n): obj is AnyRedirect & { options: { href: string } } {\n return isRedirect(obj) && !!obj.options.href\n}\n\nexport function parseRedirect(obj: any) {\n if (typeof obj === 'object' && obj.isSerializedRedirect) {\n return redirect(obj)\n }\n\n return undefined\n}\n"],"names":[],"mappings":"AAwDO,SAAS,SAOd,MACmD;AACnD,OAAK,aAAa,KAAK,cAAc,KAAK,QAAQ;
|
|
1
|
+
{"version":3,"file":"redirect.js","sources":["../../src/redirect.ts"],"sourcesContent":["import type { NavigateOptions } from './link'\nimport type { AnyRouter, RegisteredRouter } from './router'\n\nexport type AnyRedirect = Redirect<any, any, any, any, any>\n\n/**\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type Redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = Response & {\n options: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n redirectHandled?: boolean\n}\n\nexport type RedirectOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = {\n href?: string\n /**\n * @deprecated Use `statusCode` instead\n **/\n code?: number\n /**\n * The HTTP status code to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#statuscode-property)\n */\n statusCode?: number\n /**\n * If provided, will throw the redirect object instead of returning it. This can be useful in places where `throwing` in a function might cause it to have a return type of `never`. In that case, you can use `redirect({ throw: true })` to throw the redirect object instead of returning it.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#throw-property)\n */\n throw?: any\n /**\n * The HTTP headers to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#headers-property)\n */\n headers?: HeadersInit\n} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type ResolvedRedirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string = '',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport function redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = '.',\n const TFrom extends string = string,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n opts: RedirectOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> {\n opts.statusCode = opts.statusCode || opts.code || 307\n\n if (!opts.reloadDocument) {\n try {\n new URL(`${opts.href}`)\n opts.reloadDocument = true\n } catch {}\n }\n\n const headers = new Headers(opts.headers || {})\n\n const response = new Response(null, {\n status: opts.statusCode,\n headers,\n })\n\n ;(response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>).options =\n opts\n\n if (opts.throw) {\n throw response\n }\n\n return response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n}\n\nexport function isRedirect(obj: any): obj is AnyRedirect {\n return obj instanceof Response && !!(obj as any).options\n}\n\nexport function isResolvedRedirect(\n obj: any,\n): obj is AnyRedirect & { options: { href: string } } {\n return isRedirect(obj) && !!obj.options.href\n}\n\nexport function parseRedirect(obj: any) {\n if (typeof obj === 'object' && obj.isSerializedRedirect) {\n return redirect(obj)\n }\n\n return undefined\n}\n"],"names":[],"mappings":"AAwDO,SAAS,SAOd,MACmD;AACnD,OAAK,aAAa,KAAK,cAAc,KAAK,QAAQ;AAE9C,MAAA,CAAC,KAAK,gBAAgB;AACpB,QAAA;AACF,UAAI,IAAI,GAAG,KAAK,IAAI,EAAE;AACtB,WAAK,iBAAiB;AAAA,IAAA,QAChB;AAAA,IAAA;AAAA,EAAC;AAGX,QAAM,UAAU,IAAI,QAAQ,KAAK,WAAW,CAAA,CAAE;AAExC,QAAA,WAAW,IAAI,SAAS,MAAM;AAAA,IAClC,QAAQ,KAAK;AAAA,IACb;AAAA,EAAA,CACD;AAEC,WAA+D,UAC/D;AAEF,MAAI,KAAK,OAAO;AACR,UAAA;AAAA,EAAA;AAGD,SAAA;AACT;AAEO,SAAS,WAAW,KAA8B;AACvD,SAAO,eAAe,YAAY,CAAC,CAAE,IAAY;AACnD;AAEO,SAAS,mBACd,KACoD;AACpD,SAAO,WAAW,GAAG,KAAK,CAAC,CAAC,IAAI,QAAQ;AAC1C;AAEO,SAAS,cAAc,KAAU;AACtC,MAAI,OAAO,QAAQ,YAAY,IAAI,sBAAsB;AACvD,WAAO,SAAS,GAAG;AAAA,EAAA;AAGd,SAAA;AACT;"}
|
package/dist/esm/router.d.ts
CHANGED
|
@@ -391,10 +391,6 @@ export interface RouterErrorSerializer<TSerializedError> {
|
|
|
391
391
|
serialize: (err: unknown) => TSerializedError;
|
|
392
392
|
deserialize: (err: TSerializedError) => unknown;
|
|
393
393
|
}
|
|
394
|
-
export interface MatchedRoutesResult {
|
|
395
|
-
matchedRoutes: Array<AnyRoute>;
|
|
396
|
-
routeParams: Record<string, string>;
|
|
397
|
-
}
|
|
398
394
|
export type PreloadRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string | undefined = undefined, TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<Array<AnyRouteMatch> | undefined>;
|
|
399
395
|
export type MatchRouteFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string | undefined = undefined, TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<RouterCore<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory>, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>['types']['allParams'];
|
|
400
396
|
export type UpdateFn<TRouteTree extends AnyRoute, TTrailingSlashOption extends TrailingSlashOption, TDefaultStructuralSharingOption extends boolean, TRouterHistory extends RouterHistory, TDehydrated extends Record<string, any>> = (newOptions: RouterConstructorOptions<TRouteTree, TTrailingSlashOption, TDefaultStructuralSharingOption, TRouterHistory, TDehydrated>) => void;
|
package/dist/esm/router.js
CHANGED
|
@@ -194,9 +194,8 @@ class RouterCore {
|
|
|
194
194
|
},
|
|
195
195
|
opts
|
|
196
196
|
);
|
|
197
|
-
} else {
|
|
198
|
-
return this.matchRoutesInternal(pathnameOrNext, locationSearchOrOpts);
|
|
199
197
|
}
|
|
198
|
+
return this.matchRoutesInternal(pathnameOrNext, locationSearchOrOpts);
|
|
200
199
|
};
|
|
201
200
|
this.getMatchedRoutes = (pathname, routePathname) => {
|
|
202
201
|
return getMatchedRoutes({
|
|
@@ -222,173 +221,90 @@ class RouterCore {
|
|
|
222
221
|
});
|
|
223
222
|
};
|
|
224
223
|
this.buildLocation = (opts) => {
|
|
225
|
-
const build = (dest = {}
|
|
226
|
-
var _a
|
|
227
|
-
const
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const fromPath = (fromMatch == null ? void 0 : fromMatch.pathname) || this.latestLocation.pathname;
|
|
236
|
-
invariant(
|
|
237
|
-
dest.from == null || fromMatch != null,
|
|
238
|
-
"Could not find match for from: " + dest.from
|
|
239
|
-
);
|
|
240
|
-
const fromSearch = ((_a = this.state.pendingMatches) == null ? void 0 : _a.length) ? (_b = last(this.state.pendingMatches)) == null ? void 0 : _b.search : ((_c = last(fromMatches)) == null ? void 0 : _c.search) || this.latestLocation.search;
|
|
241
|
-
const stayingMatches = matchedRoutesResult == null ? void 0 : matchedRoutesResult.matchedRoutes.filter(
|
|
242
|
-
(d) => fromMatches.find((e) => e.routeId === d.id)
|
|
243
|
-
);
|
|
244
|
-
let pathname;
|
|
245
|
-
if (dest.to) {
|
|
246
|
-
const resolvePathTo = (fromMatch == null ? void 0 : fromMatch.fullPath) || ((_d = last(fromMatches)) == null ? void 0 : _d.fullPath) || this.latestLocation.pathname;
|
|
247
|
-
pathname = this.resolvePathWithBase(resolvePathTo, `${dest.to}`);
|
|
248
|
-
} else {
|
|
249
|
-
const fromRouteByFromPathRouteId = this.routesById[(_e = stayingMatches == null ? void 0 : stayingMatches.find((route) => {
|
|
250
|
-
const interpolatedPath = interpolatePath({
|
|
251
|
-
path: route.fullPath,
|
|
252
|
-
params: (matchedRoutesResult == null ? void 0 : matchedRoutesResult.routeParams) ?? {},
|
|
253
|
-
decodeCharMap: this.pathParamsDecodeCharMap
|
|
254
|
-
}).interpolatedPath;
|
|
255
|
-
const pathname2 = joinPaths([this.basepath, interpolatedPath]);
|
|
256
|
-
return pathname2 === fromPath;
|
|
257
|
-
})) == null ? void 0 : _e.id];
|
|
258
|
-
pathname = this.resolvePathWithBase(
|
|
259
|
-
fromPath,
|
|
260
|
-
(fromRouteByFromPathRouteId == null ? void 0 : fromRouteByFromPathRouteId.to) ?? fromPath
|
|
261
|
-
);
|
|
224
|
+
const build = (dest = {}) => {
|
|
225
|
+
var _a;
|
|
226
|
+
const currentLocation = dest._fromLocation || this.latestLocation;
|
|
227
|
+
const allFromMatches = this.matchRoutes(currentLocation, {
|
|
228
|
+
_buildLocation: true
|
|
229
|
+
});
|
|
230
|
+
const lastMatch = last(allFromMatches);
|
|
231
|
+
let fromId = lastMatch.fullPath;
|
|
232
|
+
if (dest.to && dest.from) {
|
|
233
|
+
fromId = dest.from;
|
|
262
234
|
}
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
235
|
+
const existingFrom = [...allFromMatches].reverse().find((d) => {
|
|
236
|
+
return d.fullPath === fromId || d.fullPath === joinPaths([fromId, "/"]);
|
|
237
|
+
});
|
|
238
|
+
if (!existingFrom) {
|
|
239
|
+
console.warn(`Could not find match for from: ${dest.from}`);
|
|
240
|
+
}
|
|
241
|
+
const fromSearch = lastMatch.search;
|
|
242
|
+
const fromParams = { ...lastMatch.params };
|
|
243
|
+
const nextTo = dest.to ? this.resolvePathWithBase(fromId, `${dest.to}`) : fromId;
|
|
244
|
+
let nextParams = (dest.params ?? true) === true ? fromParams : {
|
|
245
|
+
...fromParams,
|
|
246
|
+
...functionalUpdate(dest.params, fromParams)
|
|
267
247
|
};
|
|
248
|
+
const destRoutes = this.matchRoutes(
|
|
249
|
+
nextTo,
|
|
250
|
+
{},
|
|
251
|
+
{
|
|
252
|
+
_buildLocation: true
|
|
253
|
+
}
|
|
254
|
+
).map((d) => this.looseRoutesById[d.routeId]);
|
|
268
255
|
if (Object.keys(nextParams).length > 0) {
|
|
269
|
-
|
|
256
|
+
destRoutes.map((route) => {
|
|
270
257
|
var _a2;
|
|
271
258
|
return ((_a2 = route.options.params) == null ? void 0 : _a2.stringify) ?? route.options.stringifyParams;
|
|
272
259
|
}).filter(Boolean).forEach((fn) => {
|
|
273
260
|
nextParams = { ...nextParams, ...fn(nextParams) };
|
|
274
261
|
});
|
|
275
262
|
}
|
|
276
|
-
|
|
277
|
-
path:
|
|
263
|
+
const nextPathname = interpolatePath({
|
|
264
|
+
path: nextTo,
|
|
278
265
|
params: nextParams ?? {},
|
|
279
266
|
leaveWildcards: false,
|
|
280
267
|
leaveParams: opts.leaveParams,
|
|
281
268
|
decodeCharMap: this.pathParamsDecodeCharMap
|
|
282
269
|
}).interpolatedPath;
|
|
283
|
-
let
|
|
284
|
-
if (opts._includeValidateSearch && ((
|
|
270
|
+
let nextSearch = fromSearch;
|
|
271
|
+
if (opts._includeValidateSearch && ((_a = this.options.search) == null ? void 0 : _a.strict)) {
|
|
285
272
|
let validatedSearch = {};
|
|
286
|
-
|
|
273
|
+
destRoutes.forEach((route) => {
|
|
287
274
|
try {
|
|
288
275
|
if (route.options.validateSearch) {
|
|
289
276
|
validatedSearch = {
|
|
290
277
|
...validatedSearch,
|
|
291
278
|
...validateSearch(route.options.validateSearch, {
|
|
292
279
|
...validatedSearch,
|
|
293
|
-
...
|
|
280
|
+
...nextSearch
|
|
294
281
|
}) ?? {}
|
|
295
282
|
};
|
|
296
283
|
}
|
|
297
284
|
} catch {
|
|
298
285
|
}
|
|
299
286
|
});
|
|
300
|
-
|
|
287
|
+
nextSearch = validatedSearch;
|
|
301
288
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
} else if (route.options.preSearchFilters || route.options.postSearchFilters) {
|
|
312
|
-
const legacyMiddleware = ({
|
|
313
|
-
search: search3,
|
|
314
|
-
next
|
|
315
|
-
}) => {
|
|
316
|
-
let nextSearch = search3;
|
|
317
|
-
if ("preSearchFilters" in route.options && route.options.preSearchFilters) {
|
|
318
|
-
nextSearch = route.options.preSearchFilters.reduce(
|
|
319
|
-
(prev, next2) => next2(prev),
|
|
320
|
-
search3
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
const result = next(nextSearch);
|
|
324
|
-
if ("postSearchFilters" in route.options && route.options.postSearchFilters) {
|
|
325
|
-
return route.options.postSearchFilters.reduce(
|
|
326
|
-
(prev, next2) => next2(prev),
|
|
327
|
-
result
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
return result;
|
|
331
|
-
};
|
|
332
|
-
middlewares.push(legacyMiddleware);
|
|
333
|
-
}
|
|
334
|
-
if (opts._includeValidateSearch && route.options.validateSearch) {
|
|
335
|
-
const validate = ({ search: search3, next }) => {
|
|
336
|
-
const result = next(search3);
|
|
337
|
-
try {
|
|
338
|
-
const validatedSearch = {
|
|
339
|
-
...result,
|
|
340
|
-
...validateSearch(
|
|
341
|
-
route.options.validateSearch,
|
|
342
|
-
result
|
|
343
|
-
) ?? {}
|
|
344
|
-
};
|
|
345
|
-
return validatedSearch;
|
|
346
|
-
} catch {
|
|
347
|
-
return result;
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
middlewares.push(validate);
|
|
351
|
-
}
|
|
352
|
-
return acc.concat(middlewares);
|
|
353
|
-
},
|
|
354
|
-
[]
|
|
355
|
-
)) ?? [];
|
|
356
|
-
const final = ({ search: search3 }) => {
|
|
357
|
-
if (!dest.search) {
|
|
358
|
-
return {};
|
|
359
|
-
}
|
|
360
|
-
if (dest.search === true) {
|
|
361
|
-
return search3;
|
|
362
|
-
}
|
|
363
|
-
return functionalUpdate(dest.search, search3);
|
|
364
|
-
};
|
|
365
|
-
allMiddlewares.push(final);
|
|
366
|
-
const applyNext = (index, currentSearch) => {
|
|
367
|
-
if (index >= allMiddlewares.length) {
|
|
368
|
-
return currentSearch;
|
|
369
|
-
}
|
|
370
|
-
const middleware = allMiddlewares[index];
|
|
371
|
-
const next = (newSearch) => {
|
|
372
|
-
return applyNext(index + 1, newSearch);
|
|
373
|
-
};
|
|
374
|
-
return middleware({ search: currentSearch, next });
|
|
375
|
-
};
|
|
376
|
-
return applyNext(0, search2);
|
|
377
|
-
};
|
|
378
|
-
search = applyMiddlewares(search);
|
|
379
|
-
search = replaceEqualDeep(fromSearch, search);
|
|
380
|
-
const searchStr = this.options.stringifySearch(search);
|
|
381
|
-
const hash = dest.hash === true ? this.latestLocation.hash : dest.hash ? functionalUpdate(dest.hash, this.latestLocation.hash) : void 0;
|
|
289
|
+
nextSearch = applySearchMiddleware({
|
|
290
|
+
search: nextSearch,
|
|
291
|
+
dest,
|
|
292
|
+
destRoutes,
|
|
293
|
+
_includeValidateSearch: opts._includeValidateSearch
|
|
294
|
+
});
|
|
295
|
+
nextSearch = replaceEqualDeep(fromSearch, nextSearch);
|
|
296
|
+
const searchStr = this.options.stringifySearch(nextSearch);
|
|
297
|
+
const hash = dest.hash === true ? currentLocation.hash : dest.hash ? functionalUpdate(dest.hash, currentLocation.hash) : void 0;
|
|
382
298
|
const hashStr = hash ? `#${hash}` : "";
|
|
383
|
-
let nextState = dest.state === true ?
|
|
384
|
-
nextState = replaceEqualDeep(
|
|
299
|
+
let nextState = dest.state === true ? currentLocation.state : dest.state ? functionalUpdate(dest.state, currentLocation.state) : {};
|
|
300
|
+
nextState = replaceEqualDeep(currentLocation.state, nextState);
|
|
385
301
|
return {
|
|
386
|
-
pathname,
|
|
387
|
-
search,
|
|
302
|
+
pathname: nextPathname,
|
|
303
|
+
search: nextSearch,
|
|
388
304
|
searchStr,
|
|
389
305
|
state: nextState,
|
|
390
306
|
hash: hash ?? "",
|
|
391
|
-
href: `${
|
|
307
|
+
href: `${nextPathname}${searchStr}${hashStr}`,
|
|
392
308
|
unmaskOnReload: dest.unmaskOnReload
|
|
393
309
|
};
|
|
394
310
|
};
|
|
@@ -420,20 +336,11 @@ class RouterCore {
|
|
|
420
336
|
maskedNext = build(maskedDest);
|
|
421
337
|
}
|
|
422
338
|
}
|
|
423
|
-
const nextMatches = this.getMatchedRoutes(
|
|
424
|
-
next.pathname,
|
|
425
|
-
dest.to
|
|
426
|
-
);
|
|
427
|
-
const final = build(dest, nextMatches);
|
|
428
339
|
if (maskedNext) {
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
maskedDest == null ? void 0 : maskedDest.to
|
|
432
|
-
);
|
|
433
|
-
const maskedFinal = build(maskedDest, maskedMatches);
|
|
434
|
-
final.maskedLocation = maskedFinal;
|
|
340
|
+
const maskedFinal = build(maskedDest);
|
|
341
|
+
next.maskedLocation = maskedFinal;
|
|
435
342
|
}
|
|
436
|
-
return
|
|
343
|
+
return next;
|
|
437
344
|
};
|
|
438
345
|
if (opts.mask) {
|
|
439
346
|
return buildWithMatches(opts, {
|
|
@@ -1789,6 +1696,84 @@ function getMatchedRoutes({
|
|
|
1789
1696
|
}
|
|
1790
1697
|
return { matchedRoutes, routeParams, foundRoute };
|
|
1791
1698
|
}
|
|
1699
|
+
function applySearchMiddleware({
|
|
1700
|
+
search,
|
|
1701
|
+
dest,
|
|
1702
|
+
destRoutes,
|
|
1703
|
+
_includeValidateSearch
|
|
1704
|
+
}) {
|
|
1705
|
+
const allMiddlewares = destRoutes.reduce(
|
|
1706
|
+
(acc, route) => {
|
|
1707
|
+
var _a;
|
|
1708
|
+
const middlewares = [];
|
|
1709
|
+
if ("search" in route.options) {
|
|
1710
|
+
if ((_a = route.options.search) == null ? void 0 : _a.middlewares) {
|
|
1711
|
+
middlewares.push(...route.options.search.middlewares);
|
|
1712
|
+
}
|
|
1713
|
+
} else if (route.options.preSearchFilters || route.options.postSearchFilters) {
|
|
1714
|
+
const legacyMiddleware = ({
|
|
1715
|
+
search: search2,
|
|
1716
|
+
next
|
|
1717
|
+
}) => {
|
|
1718
|
+
let nextSearch = search2;
|
|
1719
|
+
if ("preSearchFilters" in route.options && route.options.preSearchFilters) {
|
|
1720
|
+
nextSearch = route.options.preSearchFilters.reduce(
|
|
1721
|
+
(prev, next2) => next2(prev),
|
|
1722
|
+
search2
|
|
1723
|
+
);
|
|
1724
|
+
}
|
|
1725
|
+
const result = next(nextSearch);
|
|
1726
|
+
if ("postSearchFilters" in route.options && route.options.postSearchFilters) {
|
|
1727
|
+
return route.options.postSearchFilters.reduce(
|
|
1728
|
+
(prev, next2) => next2(prev),
|
|
1729
|
+
result
|
|
1730
|
+
);
|
|
1731
|
+
}
|
|
1732
|
+
return result;
|
|
1733
|
+
};
|
|
1734
|
+
middlewares.push(legacyMiddleware);
|
|
1735
|
+
}
|
|
1736
|
+
if (_includeValidateSearch && route.options.validateSearch) {
|
|
1737
|
+
const validate = ({ search: search2, next }) => {
|
|
1738
|
+
const result = next(search2);
|
|
1739
|
+
try {
|
|
1740
|
+
const validatedSearch = {
|
|
1741
|
+
...result,
|
|
1742
|
+
...validateSearch(route.options.validateSearch, result) ?? {}
|
|
1743
|
+
};
|
|
1744
|
+
return validatedSearch;
|
|
1745
|
+
} catch {
|
|
1746
|
+
return result;
|
|
1747
|
+
}
|
|
1748
|
+
};
|
|
1749
|
+
middlewares.push(validate);
|
|
1750
|
+
}
|
|
1751
|
+
return acc.concat(middlewares);
|
|
1752
|
+
},
|
|
1753
|
+
[]
|
|
1754
|
+
) ?? [];
|
|
1755
|
+
const final = ({ search: search2 }) => {
|
|
1756
|
+
if (!dest.search) {
|
|
1757
|
+
return {};
|
|
1758
|
+
}
|
|
1759
|
+
if (dest.search === true) {
|
|
1760
|
+
return search2;
|
|
1761
|
+
}
|
|
1762
|
+
return functionalUpdate(dest.search, search2);
|
|
1763
|
+
};
|
|
1764
|
+
allMiddlewares.push(final);
|
|
1765
|
+
const applyNext = (index, currentSearch) => {
|
|
1766
|
+
if (index >= allMiddlewares.length) {
|
|
1767
|
+
return currentSearch;
|
|
1768
|
+
}
|
|
1769
|
+
const middleware = allMiddlewares[index];
|
|
1770
|
+
const next = (newSearch) => {
|
|
1771
|
+
return applyNext(index + 1, newSearch);
|
|
1772
|
+
};
|
|
1773
|
+
return middleware({ search: currentSearch, next });
|
|
1774
|
+
};
|
|
1775
|
+
return applyNext(0, search);
|
|
1776
|
+
}
|
|
1792
1777
|
export {
|
|
1793
1778
|
PathParamError,
|
|
1794
1779
|
RouterCore,
|