@tanstack/react-router 1.1.8 → 1.1.10

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.
@@ -9,8 +9,9 @@ export type TrimLeft<T extends string, S extends string> = T extends `${S}${infe
9
9
  export type TrimRight<T extends string, S extends string> = T extends `${infer U}${S}` ? U : T;
10
10
  export type Trim<T extends string, S extends string> = TrimLeft<TrimRight<T, S>, S>;
11
11
  export type RemoveUnderScores<T extends string> = Replace<Replace<TrimRight<TrimLeft<T, '/_'>, '_'>, '_/', '/'>, '/_', '/'>;
12
- export type ResolveFilePath<TParentRoute extends AnyRoute, TFilePath extends string> = TParentRoute['id'] extends RootRouteId ? TrimPathLeft<TFilePath> : Replace<TrimPathLeft<TFilePath>, TrimPathLeft<TParentRoute['types']['customId']>, ''>;
13
- export type FileRoutePath<TParentRoute extends AnyRoute, TFilePath extends string> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}` ? string : ResolveFilePath<TParentRoute, TFilePath>;
12
+ type ReplaceFirstOccurrence<T extends string, Search extends string, Replacement extends string> = T extends `${infer Prefix}${Search}${infer Suffix}` ? `${Prefix}${Replacement}${Suffix}` : T;
13
+ export type ResolveFilePath<TParentRoute extends AnyRoute, TFilePath extends string> = TParentRoute['id'] extends RootRouteId ? TrimPathLeft<TFilePath> : ReplaceFirstOccurrence<TrimPathLeft<TFilePath>, TrimPathLeft<TParentRoute['types']['customId']>, ''>;
14
+ export type FileRoutePath<TParentRoute extends AnyRoute, TFilePath extends string> = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}` ? string : ResolveFilePath<TParentRoute, TFilePath> extends `/_${infer _}` ? string : ResolveFilePath<TParentRoute, TFilePath>;
14
15
  export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = TFilePath, TPath extends RouteConstraints['TPath'] = FileRoutePath<TParentRoute, TFilePath>, TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, RemoveUnderScores<TPath>>> {
15
16
  path: TFilePath;
16
17
  constructor(path: TFilePath);
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Trim } from './fileRoute';
3
- import { AnyRoute, ReactNode } from './route';
3
+ import { AnyRoute, ReactNode, RootSearchSchema } from './route';
4
4
  import { RouteByPath, RouteIds, RoutePaths } from './routeInfo';
5
5
  import { RegisteredRouter } from './router';
6
6
  import { LinkProps, UseLinkPropsOptions } from './useNavigate';
@@ -45,7 +45,7 @@ export type ToSubOptions<TRouteTree extends AnyRoute = RegisteredRouter['routeTr
45
45
  } & CheckPath<TRouteTree, NoInfer<TResolved>, {}> & SearchParamOptions<TRouteTree, TFrom, TTo, TResolved> & PathParamOptions<TRouteTree, TFrom, TTo, TResolved>;
46
46
  type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
47
47
  type ParamVariant = 'PATH' | 'SEARCH';
48
- export type ParamOptions<TRouteTree extends AnyRoute, TFrom, TTo, TResolved, TParamVariant extends ParamVariant, TFromRouteType extends 'allParams' | 'fullSearchSchema' = TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema', TToRouteType extends 'allParams' | 'fullSearchSchemaInput' = TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchemaInput', TFromParams = Expand<RouteByPath<TRouteTree, TFrom>['types'][TFromRouteType]>, TToParams = TTo extends '' ? TFromParams : never extends TResolved ? Expand<RouteByPath<TRouteTree, TTo>['types'][TToRouteType]> : Expand<RouteByPath<TRouteTree, TResolved>['types'][TToRouteType]>, TReducer = ParamsReducer<TFromParams, TToParams>> = Expand<WithoutEmpty<PickRequired<TToParams>>> extends never ? Partial<MakeParamOption<TParamVariant, true | TReducer>> : TFromParams extends Expand<WithoutEmpty<PickRequired<TToParams>>> ? MakeParamOption<TParamVariant, true | TReducer> : MakeParamOption<TParamVariant, TReducer>;
48
+ export type ParamOptions<TRouteTree extends AnyRoute, TFrom, TTo extends string, TResolved, TParamVariant extends ParamVariant, TFromRouteType extends 'allParams' | 'fullSearchSchema' = TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema', TToRouteType extends 'allParams' | 'fullSearchSchemaInput' = TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchemaInput', TFromParams = Expand<Exclude<RouteByPath<TRouteTree, TFrom>['types'][TFromRouteType], RootSearchSchema>>, TToIndex = RouteByPath<TRouteTree, `${TTo}/`> extends never ? TTo : `${TTo}/`, TToParams = TToIndex extends '' ? TFromParams : never extends TResolved ? Expand<Exclude<RouteByPath<TRouteTree, TToIndex>['types'][TToRouteType], RootSearchSchema>> : Expand<Exclude<RouteByPath<TRouteTree, TResolved>['types'][TToRouteType], RootSearchSchema>>, TReducer = ParamsReducer<TFromParams, TToParams>> = Expand<WithoutEmpty<PickRequired<TToParams>>> extends never ? Partial<MakeParamOption<TParamVariant, true | TReducer>> : TFromParams extends Expand<WithoutEmpty<PickRequired<TToParams>>> ? MakeParamOption<TParamVariant, true | TReducer> : MakeParamOption<TParamVariant, TReducer>;
49
49
  type MakeParamOption<TParamVariant extends ParamVariant, T> = TParamVariant extends 'PATH' ? MakePathParamOptions<T> : MakeSearchParamOptions<T>;
50
50
  type MakeSearchParamOptions<T> = {
51
51
  search: T;
@@ -53,8 +53,8 @@ type MakeSearchParamOptions<T> = {
53
53
  type MakePathParamOptions<T> = {
54
54
  params: T;
55
55
  };
56
- export type SearchParamOptions<TRouteTree extends AnyRoute, TFrom, TTo, TResolved> = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'SEARCH'>;
57
- export type PathParamOptions<TRouteTree extends AnyRoute, TFrom, TTo, TResolved> = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'PATH'>;
56
+ export type SearchParamOptions<TRouteTree extends AnyRoute, TFrom, TTo extends string, TResolved> = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'SEARCH'>;
57
+ export type PathParamOptions<TRouteTree extends AnyRoute, TFrom, TTo extends string, TResolved> = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'PATH'>;
58
58
  export type ToPathOption<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> | string = string, TTo extends string = ''> = TTo | RelativeToPathAutoComplete<RoutePaths<TRouteTree>, NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
59
59
  export type ToIdOption<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> | undefined = undefined, TTo extends string = ''> = TTo | RelativeToPathAutoComplete<RouteIds<TRouteTree>, NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
60
60
  export interface ActiveOptions {
@@ -124,8 +124,8 @@ export type InferFullSearchSchemaInput<TRoute> = TRoute extends {
124
124
  fullSearchSchemaInput: infer TFullSearchSchemaInput;
125
125
  };
126
126
  } ? TFullSearchSchemaInput : {};
127
- export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<Assign<InferFullSearchSchema<TParentRoute>, TSearchSchema>>;
128
- export type ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed> = Expand<Assign<InferFullSearchSchemaInput<TParentRoute>, TSearchSchemaUsed>>;
127
+ export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<Assign<Omit<InferFullSearchSchema<TParentRoute>, keyof RootSearchSchema>, TSearchSchema>>;
128
+ export type ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed> = Expand<Assign<Omit<InferFullSearchSchemaInput<TParentRoute>, keyof RootSearchSchema>, TSearchSchemaUsed>>;
129
129
  export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
130
130
  }
131
131
  export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>;
@@ -235,8 +235,11 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
235
235
  } | undefined) => TSelected;
236
236
  }
237
237
  export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any>;
238
- export declare function rootRouteWithContext<TRouterContext extends {}>(): <TSearchSchemaInput extends Record<string, any> = {}, TSearchSchema extends Record<string, any> = {}, TSearchSchemaUsed extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends unknown = unknown>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TSearchSchemaUsed, TSearchSchema, {}, {}, TRouteContext, Assign<TRouterContext, TRouteContext>, TLoaderDeps, TLoaderData>, "path" | "id" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TRouteContext, TRouterContext, {}, unknown>;
239
- export declare class RootRoute<TSearchSchemaInput extends Record<string, any> = {}, TSearchSchema extends Record<string, any> = {}, TSearchSchemaUsed extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown> extends Route<any, // TParentRoute
238
+ export declare function rootRouteWithContext<TRouterContext extends {}>(): <TSearchSchemaInput extends Record<string, any> = RootSearchSchema, TSearchSchema extends Record<string, any> = RootSearchSchema, TSearchSchemaUsed extends Record<string, any> = RootSearchSchema, TRouteContext extends RouteContext = RouteContext, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends unknown = unknown>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TSearchSchemaUsed, TSearchSchema, {}, {}, TRouteContext, Assign<TRouterContext, TRouteContext>, TLoaderDeps, TLoaderData>, "path" | "id" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TRouteContext, TRouterContext, {}, unknown>;
239
+ export type RootSearchSchema = {
240
+ __TRootSearchSchema__: '__TRootSearchSchema__';
241
+ };
242
+ export declare class RootRoute<TSearchSchemaInput extends Record<string, any> = RootSearchSchema, TSearchSchema extends Record<string, any> = RootSearchSchema, TSearchSchemaUsed extends Record<string, any> = RootSearchSchema, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}, TLoaderDeps extends Record<string, any> = {}, TLoaderData extends any = unknown> extends Route<any, // TParentRoute
240
243
  '/', // TPath
241
244
  '/', // TFullPath
242
245
  string, // TCustomId
@@ -2367,9 +2367,8 @@
2367
2367
  const build = (dest = {}, matches) => {
2368
2368
  const from = this.latestLocation;
2369
2369
  const fromSearch = (this.state.pendingMatches || this.state.matches).at(-1)?.search || from.search;
2370
- const fromPathname = dest.from ?? from.pathname;
2371
- let pathname = this.resolvePathWithBase(fromPathname, `${dest.to ?? ''}`);
2372
- const fromMatches = this.matchRoutes(fromPathname, fromSearch);
2370
+ let pathname = this.resolvePathWithBase(from.pathname, `${dest.to ?? ''}`);
2371
+ const fromMatches = this.matchRoutes(from.pathname, fromSearch);
2373
2372
  const stayingMatches = matches?.filter(d => fromMatches?.find(e => e.routeId === d.routeId));
2374
2373
  const prevParams = {
2375
2374
  ...last(fromMatches)?.params