@tanstack/react-router 0.0.1-beta.235 → 0.0.1-beta.237

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.
Files changed (39) hide show
  1. package/build/cjs/Matches.js +31 -18
  2. package/build/cjs/Matches.js.map +1 -1
  3. package/build/cjs/RouterProvider.js +45 -25
  4. package/build/cjs/RouterProvider.js.map +1 -1
  5. package/build/cjs/index.js +1 -0
  6. package/build/cjs/index.js.map +1 -1
  7. package/build/cjs/route.js +13 -7
  8. package/build/cjs/route.js.map +1 -1
  9. package/build/cjs/router.js +49 -37
  10. package/build/cjs/router.js.map +1 -1
  11. package/build/cjs/useParams.js +7 -2
  12. package/build/cjs/useParams.js.map +1 -1
  13. package/build/cjs/useSearch.js +6 -1
  14. package/build/cjs/useSearch.js.map +1 -1
  15. package/build/cjs/utils.js +4 -1
  16. package/build/cjs/utils.js.map +1 -1
  17. package/build/esm/index.js +155 -92
  18. package/build/esm/index.js.map +1 -1
  19. package/build/stats-html.html +1 -1
  20. package/build/stats-react.json +574 -293
  21. package/build/types/Matches.d.ts +9 -3
  22. package/build/types/RouterProvider.d.ts +3 -0
  23. package/build/types/route.d.ts +30 -10
  24. package/build/types/router.d.ts +6 -3
  25. package/build/types/useParams.d.ts +3 -1
  26. package/build/types/useSearch.d.ts +3 -1
  27. package/build/types/utils.d.ts +3 -1
  28. package/build/umd/index.development.js +423 -95
  29. package/build/umd/index.development.js.map +1 -1
  30. package/build/umd/index.production.js +2 -2
  31. package/build/umd/index.production.js.map +1 -1
  32. package/package.json +4 -2
  33. package/src/Matches.tsx +70 -35
  34. package/src/RouterProvider.tsx +68 -32
  35. package/src/route.ts +37 -15
  36. package/src/router.ts +62 -44
  37. package/src/useParams.tsx +14 -4
  38. package/src/useSearch.tsx +11 -3
  39. package/src/utils.ts +20 -12
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { RouteMatch } from './Matches'\nimport { AnyRoute } from './route'\nimport { ParseRoute, RouteIds, RoutesById, RouteById } from './routeInfo'\nimport { RegisteredRouter } from './router'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\nexport type IsAny<T, Y, N = T> = 1 extends 0 & T ? Y : N\nexport type IsAnyBoolean<T> = 1 extends 0 & T ? true : false\nexport type IsKnown<T, Y, N> = unknown extends T ? N : Y\nexport type PickAsRequired<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\nexport type PickAsPartial<T, K extends keyof T> = Omit<T, K> &\n Partial<Pick<T, K>>\nexport type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never\nexport type PickExtra<T, K> = {\n [TKey in keyof K as string extends TKey\n ? never\n : TKey extends keyof T\n ? never\n : TKey]: K[TKey]\n}\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\n\n// export type Expand<T> = T\nexport type Expand<T> = T extends object\n ? T extends infer O\n ? { [K in keyof O]: O[K] }\n : never\n : T\n\nexport type UnionToIntersection<U> = (\n U extends any ? (k: U) => void : never\n) extends (k: infer I) => any\n ? I\n : never\n\n// type Compute<T> = { [K in keyof T]: T[K] } | never\n\n// type AllKeys<T> = T extends any ? keyof T : never\n\n// export type MergeUnion<T, Keys extends keyof T = keyof T> = Compute<\n// {\n// [K in Keys]: T[Keys]\n// } & {\n// [K in AllKeys<T>]?: T extends any\n// ? K extends keyof T\n// ? T[K]\n// : never\n// : never\n// }\n// >\n\nexport type Assign<Left, Right> = Omit<Left, keyof Right> & Right\n\nexport type AssignAll<T extends any[]> = T extends [infer Left, ...infer Right]\n ? Right extends any[]\n ? Assign<Left, AssignAll<Right>>\n : Left\n : {}\n\n// // Sample types to merge\n// type TypeA = {\n// shared: string\n// onlyInA: string\n// nested: {\n// shared: string\n// aProp: string\n// }\n// array: string[]\n// }\n\n// type TypeB = {\n// shared: number\n// onlyInB: number\n// nested: {\n// shared: number\n// bProp: number\n// }\n// array: number[]\n// }\n\n// type TypeC = {\n// shared: boolean\n// onlyInC: boolean\n// nested: {\n// shared: boolean\n// cProp: boolean\n// }\n// array: boolean[]\n// }\n\n// type Test = Expand<Assign<TypeA, TypeB>>\n\n// // Using DeepMerge to merge TypeA and TypeB\n// type MergedType = Expand<AssignAll<[TypeA, TypeB, TypeC]>>\n\nexport type Values<O> = O[ValueKeys<O>]\nexport type ValueKeys<O> = Extract<keyof O, PropertyKey>\n\nexport type DeepAwaited<T> = T extends Promise<infer A>\n ? DeepAwaited<A>\n : T extends Record<infer A, Promise<infer B>>\n ? { [K in A]: DeepAwaited<B> }\n : T\n\nexport type PathParamMask<TRoutePath extends string> =\n TRoutePath extends `${infer L}/$${infer C}/${infer R}`\n ? PathParamMask<`${L}/${string}/${R}`>\n : TRoutePath extends `${infer L}/$${infer C}`\n ? PathParamMask<`${L}/${string}`>\n : TRoutePath\n\nexport type Timeout = ReturnType<typeof setTimeout>\n\nexport type Updater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev?: TPrevious) => TResult)\n\nexport type NonNullableUpdater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev: TPrevious) => TResult)\n\nexport type PickExtract<T, U> = {\n [K in keyof T as T[K] extends U ? K : never]: T[K]\n}\n\nexport type PickExclude<T, U> = {\n [K in keyof T as T[K] extends U ? never : K]: T[K]\n}\n\n//\n\nexport const isServer = typeof document === 'undefined'\n\nexport function last<T>(arr: T[]) {\n return arr[arr.length - 1]\n}\n\nfunction isFunction(d: any): d is Function {\n return typeof d === 'function'\n}\n\nexport function functionalUpdate<TResult>(\n updater: Updater<TResult> | NonNullableUpdater<TResult>,\n previous: TResult,\n): TResult {\n if (isFunction(updater)) {\n return updater(previous as TResult)\n }\n\n return updater\n}\n\nexport function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K> {\n return keys.reduce((obj: any, key: K) => {\n obj[key] = parent[key]\n return obj\n }, {} as any)\n}\n\n/**\n * This function returns `a` if `b` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between immutable JSON values for example.\n * Do not use this with signals\n */\nexport function replaceEqualDeep<T>(prev: any, _next: T): T {\n if (prev === _next) {\n return prev\n }\n\n const next = _next as any\n\n const array = Array.isArray(prev) && Array.isArray(next)\n\n if (array || (isPlainObject(prev) && isPlainObject(next))) {\n const prevSize = array ? prev.length : Object.keys(prev).length\n const nextItems = array ? next : Object.keys(next)\n const nextSize = nextItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < nextSize; i++) {\n const key = array ? i : nextItems[i]\n copy[key] = replaceEqualDeep(prev[key], next[key])\n if (copy[key] === prev[key]) {\n equalItems++\n }\n }\n\n return prevSize === nextSize && equalItems === prevSize ? prev : copy\n }\n\n return next\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any) {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any) {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function deepEqual(a: any, b: any, partial: boolean = false): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (isPlainObject(a) && isPlainObject(b)) {\n const aKeys = Object.keys(a)\n const bKeys = Object.keys(b)\n\n if (!partial && aKeys.length !== bKeys.length) {\n return false\n }\n\n return !bKeys.some(\n (key) => !(key in a) || !deepEqual(a[key], b[key], partial),\n )\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n return !a.some((item, index) => !deepEqual(item, b[index], partial))\n }\n\n return false\n}\n\nexport function useStableCallback<T extends (...args: any[]) => any>(fn: T): T {\n const fnRef = React.useRef(fn)\n fnRef.current = fn\n\n const ref = React.useRef((...args: any[]) => fnRef.current(...args))\n return ref.current as T\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (let i = 0; i < keysA.length; i++) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||\n !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n\nexport type StrictOrFrom<TFrom> =\n | {\n from: TFrom\n strict?: true\n }\n | {\n from?: never\n strict: false\n }\n\nexport type RouteFromIdOrRoute<\n T,\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n> = T extends ParseRoute<TRouteTree>\n ? T\n : T extends RouteIds<TRouteTree>\n ? RoutesById<TRouteTree>[T]\n : T extends string\n ? RouteIds<TRouteTree>\n : never\n\nexport function useRouteContext<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext'],\n TSelected = TRouteContext,\n>(\n opts: StrictOrFrom<TFrom>,\n): TStrict extends true ? TSelected : TSelected | undefined {\n return useMatch(opts).context\n}\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nexport function escapeJSON(jsonString: string) {\n return jsonString\n .replace(/\\\\/g, '\\\\\\\\') // Escape backslashes\n .replace(/'/g, \"\\\\'\") // Escape single quotes\n .replace(/\"/g, '\\\\\"') // Escape double quotes\n}\n"],"names":["isServer","document","last","arr","length","isFunction","d","functionalUpdate","updater","previous","pick","parent","keys","reduce","obj","key","replaceEqualDeep","prev","_next","next","array","Array","isArray","isPlainObject","prevSize","Object","nextItems","nextSize","copy","equalItems","i","o","hasObjectPrototype","ctor","constructor","prot","prototype","hasOwnProperty","toString","call","deepEqual","a","b","partial","aKeys","bKeys","some","item","index","useStableCallback","fn","fnRef","React","useRef","current","ref","args","shallow","objA","objB","is","keysA","useRouteContext","opts","useMatch","context","useLayoutEffect","window","useEffect","escapeJSON","jsonString","replace"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;;AAaA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAoCA;;MAEaA,QAAQ,GAAG,OAAOC,QAAQ,KAAK,YAAW;AAEhD,SAASC,IAAIA,CAAIC,GAAQ,EAAE;AAChC,EAAA,OAAOA,GAAG,CAACA,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC,CAAA;AAC5B,CAAA;AAEA,SAASC,UAAUA,CAACC,CAAM,EAAiB;EACzC,OAAO,OAAOA,CAAC,KAAK,UAAU,CAAA;AAChC,CAAA;AAEO,SAASC,gBAAgBA,CAC9BC,OAAuD,EACvDC,QAAiB,EACR;AACT,EAAA,IAAIJ,UAAU,CAACG,OAAO,CAAC,EAAE;IACvB,OAAOA,OAAO,CAACC,QAAmB,CAAC,CAAA;AACrC,GAAA;AAEA,EAAA,OAAOD,OAAO,CAAA;AAChB,CAAA;AAEO,SAASE,IAAIA,CAAuBC,MAAS,EAAEC,IAAS,EAAc;EAC3E,OAAOA,IAAI,CAACC,MAAM,CAAC,CAACC,GAAQ,EAAEC,GAAM,KAAK;AACvCD,IAAAA,GAAG,CAACC,GAAG,CAAC,GAAGJ,MAAM,CAACI,GA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C1B,OAAOC,MAAM,KAAK,WAAW,GAAGf,gBAAK,CAACc,eAAe,GAAGd,gBAAK,CAACgB,UAAS;AAElE,SAASC,UAAUA,CAACC,UAAkB,EAAE;EAC7C,OAAOA,UAAU,CACdC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;AAAC,GACvBA,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;AAAC,GACrBA,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC1B;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './Matches'\nimport { RouteMatch } from './Matches'\nimport { AnyRoute } from './route'\nimport { ParseRoute, RouteIds, RoutesById, RouteById } from './routeInfo'\nimport { RegisteredRouter } from './router'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\nexport type IsAny<T, Y, N = T> = 1 extends 0 & T ? Y : N\nexport type IsAnyBoolean<T> = 1 extends 0 & T ? true : false\nexport type IsKnown<T, Y, N> = unknown extends T ? N : Y\nexport type PickAsRequired<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\nexport type PickAsPartial<T, K extends keyof T> = Omit<T, K> &\n Partial<Pick<T, K>>\nexport type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never\nexport type PickExtra<T, K> = {\n [TKey in keyof K as string extends TKey\n ? never\n : TKey extends keyof T\n ? never\n : TKey]: K[TKey]\n}\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\n\n// export type Expand<T> = T\nexport type Expand<T> = T extends object\n ? T extends infer O\n ? { [K in keyof O]: O[K] }\n : never\n : T\n\nexport type UnionToIntersection<U> = (\n U extends any ? (k: U) => void : never\n) extends (k: infer I) => any\n ? I\n : never\n\n// type Compute<T> = { [K in keyof T]: T[K] } | never\n\n// type AllKeys<T> = T extends any ? keyof T : never\n\n// export type MergeUnion<T, Keys extends keyof T = keyof T> = Compute<\n// {\n// [K in Keys]: T[Keys]\n// } & {\n// [K in AllKeys<T>]?: T extends any\n// ? K extends keyof T\n// ? T[K]\n// : never\n// : never\n// }\n// >\n\nexport type Assign<Left, Right> = Omit<Left, keyof Right> & Right\n\nexport type AssignAll<T extends any[]> = T extends [infer Left, ...infer Right]\n ? Right extends any[]\n ? Assign<Left, AssignAll<Right>>\n : Left\n : {}\n\n// // Sample types to merge\n// type TypeA = {\n// shared: string\n// onlyInA: string\n// nested: {\n// shared: string\n// aProp: string\n// }\n// array: string[]\n// }\n\n// type TypeB = {\n// shared: number\n// onlyInB: number\n// nested: {\n// shared: number\n// bProp: number\n// }\n// array: number[]\n// }\n\n// type TypeC = {\n// shared: boolean\n// onlyInC: boolean\n// nested: {\n// shared: boolean\n// cProp: boolean\n// }\n// array: boolean[]\n// }\n\n// type Test = Expand<Assign<TypeA, TypeB>>\n\n// // Using DeepMerge to merge TypeA and TypeB\n// type MergedType = Expand<AssignAll<[TypeA, TypeB, TypeC]>>\n\nexport type Values<O> = O[ValueKeys<O>]\nexport type ValueKeys<O> = Extract<keyof O, PropertyKey>\n\nexport type DeepAwaited<T> = T extends Promise<infer A>\n ? DeepAwaited<A>\n : T extends Record<infer A, Promise<infer B>>\n ? { [K in A]: DeepAwaited<B> }\n : T\n\nexport type PathParamMask<TRoutePath extends string> =\n TRoutePath extends `${infer L}/$${infer C}/${infer R}`\n ? PathParamMask<`${L}/${string}/${R}`>\n : TRoutePath extends `${infer L}/$${infer C}`\n ? PathParamMask<`${L}/${string}`>\n : TRoutePath\n\nexport type Timeout = ReturnType<typeof setTimeout>\n\nexport type Updater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev?: TPrevious) => TResult)\n\nexport type NonNullableUpdater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev: TPrevious) => TResult)\n\nexport type PickExtract<T, U> = {\n [K in keyof T as T[K] extends U ? K : never]: T[K]\n}\n\nexport type PickExclude<T, U> = {\n [K in keyof T as T[K] extends U ? never : K]: T[K]\n}\n\n//\n\nexport const isServer = typeof document === 'undefined'\n\nexport function last<T>(arr: T[]) {\n return arr[arr.length - 1]\n}\n\nfunction isFunction(d: any): d is Function {\n return typeof d === 'function'\n}\n\nexport function functionalUpdate<TResult>(\n updater: Updater<TResult> | NonNullableUpdater<TResult>,\n previous: TResult,\n): TResult {\n if (isFunction(updater)) {\n return updater(previous as TResult)\n }\n\n return updater\n}\n\nexport function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K> {\n return keys.reduce((obj: any, key: K) => {\n obj[key] = parent[key]\n return obj\n }, {} as any)\n}\n\n/**\n * This function returns `a` if `b` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between immutable JSON values for example.\n * Do not use this with signals\n */\nexport function replaceEqualDeep<T>(prev: any, _next: T): T {\n if (prev === _next) {\n return prev\n }\n\n const next = _next as any\n\n const array = Array.isArray(prev) && Array.isArray(next)\n\n if (array || (isPlainObject(prev) && isPlainObject(next))) {\n const prevSize = array ? prev.length : Object.keys(prev).length\n const nextItems = array ? next : Object.keys(next)\n const nextSize = nextItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < nextSize; i++) {\n const key = array ? i : nextItems[i]\n copy[key] = replaceEqualDeep(prev[key], next[key])\n if (copy[key] === prev[key]) {\n equalItems++\n }\n }\n\n return prevSize === nextSize && equalItems === prevSize ? prev : copy\n }\n\n return next\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any) {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any) {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function deepEqual(a: any, b: any, partial: boolean = false): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (isPlainObject(a) && isPlainObject(b)) {\n const aKeys = Object.keys(a)\n const bKeys = Object.keys(b)\n\n if (!partial && aKeys.length !== bKeys.length) {\n return false\n }\n\n return !bKeys.some(\n (key) => !(key in a) || !deepEqual(a[key], b[key], partial),\n )\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n return !a.some((item, index) => !deepEqual(item, b[index], partial))\n }\n\n return false\n}\n\nexport function useStableCallback<T extends (...args: any[]) => any>(fn: T): T {\n const fnRef = React.useRef(fn)\n fnRef.current = fn\n\n const ref = React.useRef((...args: any[]) => fnRef.current(...args))\n return ref.current as T\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (let i = 0; i < keysA.length; i++) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||\n !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n\nexport type StrictOrFrom<TFrom> =\n | {\n from: TFrom\n strict?: true\n }\n | {\n from?: never\n strict: false\n }\n\nexport type RouteFromIdOrRoute<\n T,\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n> = T extends ParseRoute<TRouteTree>\n ? T\n : T extends RouteIds<TRouteTree>\n ? RoutesById<TRouteTree>[T]\n : T extends string\n ? RouteIds<TRouteTree>\n : never\n\nexport function useRouteContext<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext'],\n TSelected = TRouteContext,\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (search: TRouteContext) => TSelected\n },\n): TStrict extends true ? TSelected : TSelected | undefined {\n return useMatch({\n ...(opts as any),\n select: (match: RouteMatch) =>\n opts?.select\n ? opts.select(match.context as TRouteContext)\n : match.context,\n })\n}\n\nexport const useLayoutEffect =\n typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nexport function escapeJSON(jsonString: string) {\n return jsonString\n .replace(/\\\\/g, '\\\\\\\\') // Escape backslashes\n .replace(/'/g, \"\\\\'\") // Escape single quotes\n .replace(/\"/g, '\\\\\"') // Escape double quotes\n}\n"],"names":["isServer","document","last","arr","length","isFunction","d","functionalUpdate","updater","previous","pick","parent","keys","reduce","obj","key","replaceEqualDeep","prev","_next","next","array","Array","isArray","isPlainObject","prevSize","Object","nextItems","nextSize","copy","equalItems","i","o","hasObjectPrototype","ctor","constructor","prot","prototype","hasOwnProperty","toString","call","deepEqual","a","b","partial","aKeys","bKeys","some","item","index","useStableCallback","fn","fnRef","React","useRef","current","ref","args","shallow","objA","objB","is","keysA","useRouteContext","opts","useMatch","select","match","context","useLayoutEffect","window","useEffect","escapeJSON","jsonString","replace"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;;AAaA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAoCA;;MAEaA,QAAQ,GAAG,OAAOC,QAAQ,KAAK,YAAW;AAEhD,SAASC,IAAIA,CAAIC,GAAQ,EAAE;AAChC,EAAA,OAAOA,GAAG,CAACA,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC,CAAA;AA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,IAAA,IACE,CAACL,MAAM,CAACW,SAAS,CAACC,cAAc,CAACE,IAAI,CAACoB,IAAI,EAAEE,KAAK,CAAC/B,CAAC,CAAW,CAAC,IAC/D,CAACL,MAAM,CAACmC,EAAE,CAACF,IAAI,CAACG,KAAK,CAAC/B,CAAC,CAAC,CAAY,EAAE6B,IAAI,CAACE,KAAK,CAAC/B,CAAC,CAAC,CAAY,CAAC,EAChE;AACA,MAAA,OAAO,KAAK,CAAA;AACd,KAAA;AACF,GAAA;AACA,EAAA,OAAO,IAAI,CAAA;AACb,CAAA;AAuBO,SAASgC,eAAeA,CAO7BC,IAEC,EACyD;AAC1D,EAAA,OAAOC,gBAAQ,CAAC;AACd,IAAA,GAAID,IAAY;AAChBE,IAAAA,MAAM,EAAGC,KAAiB,IACxBH,IAAI,EAAEE,MAAM,GACRF,IAAI,CAACE,MAAM,CAACC,KAAK,CAACC,OAAwB,CAAC,GAC3CD,KAAK,CAACC,OAAAA;AACd,GAAC,CAAC,CAAA;AACJ,CAAA;AAEaC,MAAAA,eAAe,GAC1B,OAAOC,MAAM,KAAK,WAAW,GAAGjB,gBAAK,CAACgB,eAAe,GAAGhB,gBAAK,CAACkB,UAAS;AAElE,SAASC,UAAUA,CAACC,UAAkB,EAAE;EAC7C,OAAOA,UAAU,CACdC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;AAAC,GACvBA,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;AAAC,GACrBA,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC1B;;;;;;;;;;;;;;;"}
@@ -15,6 +15,8 @@ export { default as invariant } from 'tiny-invariant';
15
15
  import warning from 'tiny-warning';
16
16
  export { default as warning } from 'tiny-warning';
17
17
  import * as React from 'react';
18
+ import { useStore } from '@tanstack/react-store';
19
+ import { Store } from '@tanstack/store';
18
20
 
19
21
  function CatchBoundary(props) {
20
22
  const errorComponent = props.errorComponent ?? ErrorComponent;
@@ -282,7 +284,10 @@ function shallow(objA, objB) {
282
284
  return true;
283
285
  }
284
286
  function useRouteContext(opts) {
285
- return useMatch(opts).context;
287
+ return useMatch({
288
+ ...opts,
289
+ select: match => opts?.select ? opts.select(match.context) : match.context
290
+ });
286
291
  }
287
292
  const useLayoutEffect$1 = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
288
293
  function escapeJSON(jsonString) {
@@ -475,12 +480,22 @@ function matchByPath(basepath, from, matchLocation) {
475
480
  return isMatch ? params : undefined;
476
481
  }
477
482
 
478
- function useParams(_opts) {
479
- return last(useRouter().state.matches)?.params;
483
+ function useParams(opts) {
484
+ return useRouterState({
485
+ select: state => {
486
+ const params = last(state.matches)?.params;
487
+ return opts?.select ? opts.select(params) : params;
488
+ }
489
+ });
480
490
  }
481
491
 
482
492
  function useSearch(opts) {
483
- return useMatch(opts).search;
493
+ return useMatch({
494
+ ...opts,
495
+ select: match => {
496
+ return opts?.select ? opts.select(match.search) : match.search;
497
+ }
498
+ });
484
499
  }
485
500
 
486
501
  const rootRouteId = '__root__';
@@ -545,28 +560,34 @@ class Route {
545
560
  // This is a dummy static method that should get
546
561
  // replaced by a framework specific implementation if necessary
547
562
  };
548
- useMatch = () => {
563
+ useMatch = opts => {
549
564
  return useMatch({
565
+ ...opts,
550
566
  from: this.id
551
567
  });
552
568
  };
553
- useRouteContext = () => {
569
+ useRouteContext = opts => {
554
570
  return useMatch({
555
- from: this.id
556
- }).context;
571
+ ...opts,
572
+ from: this.id,
573
+ select: d => opts?.select ? opts.select(d.context) : d.context
574
+ });
557
575
  };
558
- useSearch = () => {
576
+ useSearch = opts => {
559
577
  return useSearch({
578
+ ...opts,
560
579
  from: this.id
561
580
  });
562
581
  };
563
- useParams = () => {
582
+ useParams = opts => {
564
583
  return useParams({
584
+ ...opts,
565
585
  from: this.id
566
586
  });
567
587
  };
568
- useLoaderData = () => {
588
+ useLoaderData = opts => {
569
589
  return useLoaderData({
590
+ ...opts,
570
591
  from: this.id
571
592
  });
572
593
  };
@@ -589,10 +610,9 @@ function createRouteMask(opts) {
589
610
 
590
611
  function Matches() {
591
612
  const router = useRouter();
592
- const {
593
- matches
594
- } = router.state;
595
- const locationKey = router.state.location.state.key;
613
+ const routerState = useRouterState();
614
+ const matches = routerState.pendingMatches?.some(d => d.showPending) ? routerState.pendingMatches : routerState.matches;
615
+ const locationKey = router.latestLocation.state.key;
596
616
  const route = router.routesById[rootRouteId];
597
617
  const errorComponent = React.useCallback(props => {
598
618
  return /*#__PURE__*/React.createElement(ErrorComponent, {
@@ -733,31 +753,45 @@ function MatchRoute(props) {
733
753
  return !!params ? props.children : null;
734
754
  }
735
755
  function useMatch(opts) {
736
- const router = useRouter();
737
756
  const nearestMatch = React.useContext(matchesContext)[0];
738
757
  const nearestMatchRouteId = nearestMatch?.routeId;
739
- const matchRouteId = (() => {
740
- const match = opts?.from ? router.state.matches.find(d => d.routeId === opts?.from) : router.state.matches.find(d => d.id === nearestMatch.id);
741
- return match.routeId;
742
- })();
758
+ const matchRouteId = useRouterState({
759
+ select: state => {
760
+ const matches = state.pendingMatches?.some(d => d.showPending) ? state.pendingMatches : state.matches;
761
+ const match = opts?.from ? matches.find(d => d.routeId === opts?.from) : matches.find(d => d.id === nearestMatch.id);
762
+ return match.routeId;
763
+ }
764
+ });
743
765
  if (opts?.strict ?? true) {
744
766
  invariant(nearestMatchRouteId == matchRouteId, `useMatch("${matchRouteId}") is being called in a component that is meant to render the '${nearestMatchRouteId}' route. Did you mean to 'useMatch("${matchRouteId}", { strict: false })' or 'useRoute("${matchRouteId}")' instead?`);
745
767
  }
746
- const matchSelection = (() => {
747
- const match = opts?.from ? router.state.matches.find(d => d.routeId === opts?.from) : router.state.matches.find(d => d.id === nearestMatch.id);
748
- invariant(match, `Could not find ${opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
749
- return match;
750
- })();
768
+ const matchSelection = useRouterState({
769
+ select: state => {
770
+ const matches = state.pendingMatches?.some(d => d.showPending) ? state.pendingMatches : state.matches;
771
+ const match = opts?.from ? matches.find(d => d.routeId === opts?.from) : matches.find(d => d.id === nearestMatch.id);
772
+ invariant(match, `Could not find ${opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
773
+ return opts?.select ? opts.select(match) : match;
774
+ }
775
+ });
751
776
  return matchSelection;
752
777
  }
753
778
  const matchesContext = /*#__PURE__*/React.createContext(null);
754
- function useMatches() {
755
- const router = useRouter();
779
+ function useMatches(opts) {
756
780
  const contextMatches = React.useContext(matchesContext);
757
- return router.state.matches.slice(router.state.matches.findIndex(d => d.id === contextMatches[0]?.id));
781
+ return useRouterState({
782
+ select: state => {
783
+ let matches = state.pendingMatches?.some(d => d.showPending) ? state.pendingMatches : state.matches;
784
+ matches = matches.slice(matches.findIndex(d => d.id === contextMatches[0]?.id));
785
+ return opts?.select ? opts.select(matches) : matches;
786
+ }
787
+ });
758
788
  }
759
789
  function useLoaderData(opts) {
760
- return useMatch(opts)?.loaderData;
790
+ const match = useMatch({
791
+ ...opts,
792
+ select: undefined
793
+ });
794
+ return typeof opts.select === 'function' ? opts.select(match?.loaderData) : match?.loaderData;
761
795
  }
762
796
 
763
797
  const routerContext = /*#__PURE__*/React.createContext(null);
@@ -777,9 +811,11 @@ function RouterProvider({
777
811
  ...rest?.context
778
812
  }
779
813
  });
780
- const inner = /*#__PURE__*/React.createElement(RouterProviderInner, {
814
+ const inner = /*#__PURE__*/React.createElement(routerContext.Provider, {
815
+ value: router
816
+ }, /*#__PURE__*/React.createElement(RouterProviderInner, {
781
817
  router: router
782
- });
818
+ }));
783
819
  if (router.options.Wrap) {
784
820
  return /*#__PURE__*/React.createElement(router.options.Wrap, null, inner);
785
821
  }
@@ -788,20 +824,32 @@ function RouterProvider({
788
824
  function RouterProviderInner({
789
825
  router
790
826
  }) {
791
- const [preState, setState] = React.useState(() => router.state);
827
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Matches, null), /*#__PURE__*/React.createElement(Transitioner, null));
828
+ }
829
+ function Transitioner() {
830
+ const router = useRouter();
831
+ const routerState = useRouterState({
832
+ select: s => pick(s, ['isLoading', 'location', 'resolvedLocation', 'isTransitioning'])
833
+ });
792
834
  const [isTransitioning, startReactTransition] = React.useTransition();
793
- const isAnyTransitioning = isTransitioning || preState.matches.some(d => d.status === 'pending');
794
- const state = React.useMemo(() => ({
795
- ...preState,
796
- status: isAnyTransitioning ? 'pending' : 'idle',
797
- location: isTransitioning ? router.latestLocation : preState.location,
798
- pendingMatches: router.pendingMatches
799
- }), [preState, isTransitioning]);
800
- router.setState = setState;
801
- router.state = state;
802
835
  router.startReactTransition = startReactTransition;
836
+ React.useEffect(() => {
837
+ if (isTransitioning) {
838
+ router.__store.setState(s => ({
839
+ ...s,
840
+ isTransitioning
841
+ }));
842
+ }
843
+ }, [isTransitioning]);
803
844
  const tryLoad = () => {
804
- startReactTransition(() => {
845
+ const apply = cb => {
846
+ if (!routerState.isTransitioning) {
847
+ startReactTransition(() => cb());
848
+ } else {
849
+ cb();
850
+ }
851
+ };
852
+ apply(() => {
805
853
  try {
806
854
  router.load();
807
855
  } catch (err) {
@@ -812,7 +860,7 @@ function RouterProviderInner({
812
860
  useLayoutEffect$1(() => {
813
861
  const unsub = router.history.subscribe(() => {
814
862
  router.latestLocation = router.parseLocation(router.latestLocation);
815
- if (state.location !== router.latestLocation) {
863
+ if (routerState.location !== router.latestLocation) {
816
864
  tryLoad();
817
865
  }
818
866
  });
@@ -822,7 +870,7 @@ function RouterProviderInner({
822
870
  hash: true,
823
871
  state: true
824
872
  });
825
- if (state.location.href !== nextLocation.href) {
873
+ if (routerState.location.href !== nextLocation.href) {
826
874
  router.commitLocation({
827
875
  ...nextLocation,
828
876
  replace: true
@@ -833,31 +881,35 @@ function RouterProviderInner({
833
881
  };
834
882
  }, [router.history]);
835
883
  useLayoutEffect$1(() => {
836
- if (!isTransitioning && state.resolvedLocation !== state.location) {
884
+ if (!isTransitioning && !routerState.isLoading && routerState.resolvedLocation !== routerState.location) {
885
+ console.log('onResolved', routerState.location);
837
886
  router.emit({
838
887
  type: 'onResolved',
839
- fromLocation: state.resolvedLocation,
840
- toLocation: state.location,
841
- pathChanged: state.location.href !== state.resolvedLocation?.href
888
+ fromLocation: routerState.resolvedLocation,
889
+ toLocation: routerState.location,
890
+ pathChanged: routerState.location.href !== routerState.resolvedLocation?.href
842
891
  });
843
892
  router.pendingMatches = [];
844
- setState(s => ({
893
+ router.__store.setState(s => ({
845
894
  ...s,
895
+ isTransitioning: false,
846
896
  resolvedLocation: s.location
847
897
  }));
848
898
  }
849
- });
899
+ }, [isTransitioning, routerState.isLoading]);
850
900
  useLayoutEffect$1(() => {
851
901
  if (!window.__TSR_DEHYDRATED__) {
852
902
  tryLoad();
853
903
  }
854
904
  }, []);
855
- return /*#__PURE__*/React.createElement(routerContext.Provider, {
856
- value: router
857
- }, /*#__PURE__*/React.createElement(Matches, null));
905
+ return null;
858
906
  }
859
907
  function getRouteMatch(state, id) {
860
- return [...state.pendingMatches, ...state.matches].find(d => d.id === id);
908
+ return [...(state.pendingMatches ?? []), ...state.matches].find(d => d.id === id);
909
+ }
910
+ function useRouterState(opts) {
911
+ const router = useRouter();
912
+ return useStore(router.__store, opts?.select);
861
913
  }
862
914
  function useRouter() {
863
915
  const resolvedContext = typeof document !== 'undefined' ? window.__TSR_ROUTER_CONTEXT__ || routerContext : routerContext;
@@ -1220,9 +1272,6 @@ class Router {
1220
1272
  // by the router provider once rendered. We provide these so that the
1221
1273
  // router can be used in a non-react environment if necessary
1222
1274
  startReactTransition = fn => fn();
1223
- setState = updater => {
1224
- this.state = functionalUpdate(updater, this.state);
1225
- };
1226
1275
  update = newOptions => {
1227
1276
  this.options = {
1228
1277
  ...this.options,
@@ -1237,10 +1286,20 @@ class Router {
1237
1286
  this.routeTree = this.options.routeTree;
1238
1287
  this.buildRouteTree();
1239
1288
  }
1240
- if (!this.state) {
1241
- this.state = getInitialRouterState(this.latestLocation);
1289
+ if (!this.__store) {
1290
+ this.__store = new Store(getInitialRouterState(this.latestLocation), {
1291
+ onUpdate: () => {
1292
+ this.__store.state = {
1293
+ ...this.state,
1294
+ status: this.state.isTransitioning || this.state.isLoading ? 'pending' : 'idle'
1295
+ };
1296
+ }
1297
+ });
1242
1298
  }
1243
1299
  };
1300
+ get state() {
1301
+ return this.__store.state;
1302
+ }
1244
1303
  buildRouteTree = () => {
1245
1304
  this.routesById = {};
1246
1305
  this.routesByPath = {};
@@ -1512,7 +1571,7 @@ class Router {
1512
1571
  getRouteMatch(this.state, id)?.abortController?.abort();
1513
1572
  };
1514
1573
  cancelMatches = () => {
1515
- this.state.matches.forEach(match => {
1574
+ this.state.pendingMatches?.forEach(match => {
1516
1575
  this.cancelMatch(match.id);
1517
1576
  });
1518
1577
  };
@@ -1703,6 +1762,12 @@ class Router {
1703
1762
  }) => {
1704
1763
  let latestPromise;
1705
1764
  let firstBadMatchIndex;
1765
+ const updatePendingMatch = match => {
1766
+ this.__store.setState(s => ({
1767
+ ...s,
1768
+ pendingMatches: s.pendingMatches?.map(d => d.id === match.id ? match : d)
1769
+ }));
1770
+ };
1706
1771
 
1707
1772
  // Check each match middleware to see if the route can be accessed
1708
1773
  try {
@@ -1859,12 +1924,10 @@ class Router {
1859
1924
  loadPromise
1860
1925
  };
1861
1926
  if (!preload) {
1862
- this.setState(s => ({
1863
- ...s,
1864
- matches: s.matches.map(d => d.id === match.id ? match : d)
1865
- }));
1927
+ updatePendingMatch(match);
1866
1928
  }
1867
1929
  let didShowPending = false;
1930
+ const pendingMinMs = route.options.pendingMinMs ?? this.options.defaultPendingMinMs;
1868
1931
  await new Promise(async resolve => {
1869
1932
  // If the route has a pending component and a pendingMs option,
1870
1933
  // forcefully show the pending component
@@ -1876,17 +1939,13 @@ class Router {
1876
1939
  ...match,
1877
1940
  showPending: true
1878
1941
  };
1879
- this.setState(s => ({
1880
- ...s,
1881
- matches: s.matches.map(d => d.id === match.id ? match : d)
1882
- }));
1942
+ updatePendingMatch(match);
1883
1943
  resolve();
1884
1944
  });
1885
1945
  }
1886
1946
  try {
1887
1947
  const loaderData = await loadPromise;
1888
1948
  if (latestPromise = checkLatest()) return await latestPromise;
1889
- const pendingMinMs = route.options.pendingMinMs ?? this.options.defaultPendingMinMs;
1890
1949
  if (didShowPending && pendingMinMs) {
1891
1950
  await new Promise(r => setTimeout(r, pendingMinMs));
1892
1951
  }
@@ -1916,12 +1975,19 @@ class Router {
1916
1975
  isFetching: false,
1917
1976
  updatedAt: Date.now()
1918
1977
  };
1978
+ } finally {
1979
+ // If we showed the pending component, that means
1980
+ // we already moved the pendingMatches to the matches
1981
+ // state, so we need to update that specific match
1982
+ if (didShowPending && pendingMinMs && match.showPending) {
1983
+ this.__store.setState(s => ({
1984
+ ...s,
1985
+ matches: s.matches?.map(d => d.id === match.id ? match : d)
1986
+ }));
1987
+ }
1919
1988
  }
1920
1989
  if (!preload) {
1921
- this.setState(s => ({
1922
- ...s,
1923
- matches: s.matches.map(d => d.id === match.id ? match : d)
1924
- }));
1990
+ updatePendingMatch(match);
1925
1991
  }
1926
1992
  resolve();
1927
1993
  });
@@ -1950,24 +2016,23 @@ class Router {
1950
2016
  });
1951
2017
 
1952
2018
  // Match the routes
1953
- let matches = this.matchRoutes(next.pathname, next.search, {
2019
+ let pendingMatches = this.matchRoutes(next.pathname, next.search, {
1954
2020
  debug: true
1955
2021
  });
1956
- this.pendingMatches = matches;
1957
2022
  const previousMatches = this.state.matches;
1958
2023
 
1959
2024
  // Ingest the new matches
1960
- this.setState(s => ({
2025
+ this.__store.setState(s => ({
1961
2026
  ...s,
1962
- // status: 'pending',
2027
+ isLoading: true,
1963
2028
  location: next,
1964
- matches
2029
+ pendingMatches
1965
2030
  }));
1966
2031
  try {
1967
2032
  try {
1968
2033
  // Load the matches
1969
2034
  await this.loadMatches({
1970
- matches,
2035
+ matches: pendingMatches,
1971
2036
  checkLatest: () => this.checkLatest(promise),
1972
2037
  invalidate: opts?.invalidate
1973
2038
  });
@@ -1982,14 +2047,13 @@ class Router {
1982
2047
  }
1983
2048
  const exitingMatchIds = previousMatches.filter(id => !this.pendingMatches.includes(id));
1984
2049
  const enteringMatchIds = this.pendingMatches.filter(id => !previousMatches.includes(id));
1985
- const stayingMatchIds = previousMatches.filter(id => this.pendingMatches.includes(id))
1986
-
1987
- // setState((s) => ({
1988
- // ...s,
1989
- // status: 'idle',
1990
- // resolvedLocation: s.location,
1991
- // matches,
1992
- // }))
2050
+ const stayingMatchIds = previousMatches.filter(id => this.pendingMatches.includes(id));
2051
+ this.__store.setState(s => ({
2052
+ ...s,
2053
+ isLoading: false,
2054
+ matches: pendingMatches,
2055
+ pendingMatches: undefined
2056
+ }))
1993
2057
 
1994
2058
  //
1995
2059
  ;
@@ -2144,9 +2208,6 @@ class Router {
2144
2208
  return false;
2145
2209
  }
2146
2210
  const baseLocation = opts?.pending ? this.latestLocation : this.state.resolvedLocation;
2147
-
2148
- // const baseLocation = state.resolvedLocation
2149
-
2150
2211
  if (!baseLocation) {
2151
2212
  return false;
2152
2213
  }
@@ -2218,7 +2279,7 @@ class Router {
2218
2279
  }
2219
2280
  return match;
2220
2281
  });
2221
- this.setState(s => {
2282
+ this.__store.setState(s => {
2222
2283
  return {
2223
2284
  ...s,
2224
2285
  matches: matches
@@ -2249,6 +2310,8 @@ class SearchParamError extends Error {}
2249
2310
  class PathParamError extends Error {}
2250
2311
  function getInitialRouterState(location) {
2251
2312
  return {
2313
+ isLoading: false,
2314
+ isTransitioning: false,
2252
2315
  status: 'idle',
2253
2316
  resolvedLocation: location,
2254
2317
  location,
@@ -2480,5 +2543,5 @@ function Navigate(props) {
2480
2543
  return null;
2481
2544
  }
2482
2545
 
2483
- export { Await, Block, CatchBoundary, CatchBoundaryImpl, ErrorComponent, FileRoute, Link, Match, MatchRoute, Matches, Navigate, Outlet, PathParamError, RootRoute, Route, Router, RouterProvider, ScrollRestoration, SearchParamError, cleanPath, componentTypes, createRouteMask, decode, deepEqual, defaultParseSearch, defaultStringifySearch, defer, encode, escapeJSON, functionalUpdate, getInitialRouterState, getRouteMatch, interpolatePath, isDehydratedDeferred, isPlainObject, isRedirect, isServer, joinPaths, last, lazyFn, lazyRouteComponent, matchByPath, matchPathname, matchesContext, parsePathname, parseSearchWith, pick, redirect, replaceEqualDeep, resolvePath, rootRouteId, rootRouteWithContext, routerContext, shallow, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, typedNavigate, useAwaited, useBlocker, useElementScrollRestoration, useLayoutEffect$1 as useLayoutEffect, useLinkProps, useLoaderData, useMatch, useMatchRoute, useMatches, useNavigate, useParams, useRouteContext, useRouter, useScrollRestoration, useSearch, useStableCallback };
2546
+ export { Await, Block, CatchBoundary, CatchBoundaryImpl, ErrorComponent, FileRoute, Link, Match, MatchRoute, Matches, Navigate, Outlet, PathParamError, RootRoute, Route, Router, RouterProvider, ScrollRestoration, SearchParamError, cleanPath, componentTypes, createRouteMask, decode, deepEqual, defaultParseSearch, defaultStringifySearch, defer, encode, escapeJSON, functionalUpdate, getInitialRouterState, getRouteMatch, interpolatePath, isDehydratedDeferred, isPlainObject, isRedirect, isServer, joinPaths, last, lazyFn, lazyRouteComponent, matchByPath, matchPathname, matchesContext, parsePathname, parseSearchWith, pick, redirect, replaceEqualDeep, resolvePath, rootRouteId, rootRouteWithContext, routerContext, shallow, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, typedNavigate, useAwaited, useBlocker, useElementScrollRestoration, useLayoutEffect$1 as useLayoutEffect, useLinkProps, useLoaderData, useMatch, useMatchRoute, useMatches, useNavigate, useParams, useRouteContext, useRouter, useRouterState, useScrollRestoration, useSearch, useStableCallback };
2484
2547
  //# sourceMappingURL=index.js.map