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

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 +34 -19
  2. package/build/cjs/Matches.js.map +1 -1
  3. package/build/cjs/RouterProvider.js +31 -26
  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 +144 -94
  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 +412 -97
  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 +72 -37
  34. package/src/RouterProvider.tsx +42 -31
  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
  };
@@ -588,12 +609,13 @@ function createRouteMask(opts) {
588
609
  //
589
610
 
590
611
  function Matches() {
591
- const router = useRouter();
592
612
  const {
593
- matches
594
- } = router.state;
595
- const locationKey = router.state.location.state.key;
596
- const route = router.routesById[rootRouteId];
613
+ routesById
614
+ } = useRouter();
615
+ const routerState = useRouterState();
616
+ const matches = routerState.pendingMatches?.some(d => d.showPending) ? routerState.pendingMatches : routerState.matches;
617
+ const locationKey = useRouterState().location.state.key;
618
+ const route = routesById[rootRouteId];
597
619
  const errorComponent = React.useCallback(props => {
598
620
  return /*#__PURE__*/React.createElement(ErrorComponent, {
599
621
  ...props,
@@ -733,31 +755,45 @@ function MatchRoute(props) {
733
755
  return !!params ? props.children : null;
734
756
  }
735
757
  function useMatch(opts) {
736
- const router = useRouter();
737
758
  const nearestMatch = React.useContext(matchesContext)[0];
738
759
  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
- })();
760
+ const matchRouteId = useRouterState({
761
+ select: state => {
762
+ const matches = state.pendingMatches?.some(d => d.showPending) ? state.pendingMatches : state.matches;
763
+ const match = opts?.from ? matches.find(d => d.routeId === opts?.from) : matches.find(d => d.id === nearestMatch.id);
764
+ return match.routeId;
765
+ }
766
+ });
743
767
  if (opts?.strict ?? true) {
744
768
  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
769
  }
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
- })();
770
+ const matchSelection = useRouterState({
771
+ select: state => {
772
+ const matches = state.pendingMatches?.some(d => d.showPending) ? state.pendingMatches : state.matches;
773
+ const match = opts?.from ? matches.find(d => d.routeId === opts?.from) : matches.find(d => d.id === nearestMatch.id);
774
+ invariant(match, `Could not find ${opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
775
+ return opts?.select ? opts.select(match) : match;
776
+ }
777
+ });
751
778
  return matchSelection;
752
779
  }
753
780
  const matchesContext = /*#__PURE__*/React.createContext(null);
754
- function useMatches() {
755
- const router = useRouter();
781
+ function useMatches(opts) {
756
782
  const contextMatches = React.useContext(matchesContext);
757
- return router.state.matches.slice(router.state.matches.findIndex(d => d.id === contextMatches[0]?.id));
783
+ return useRouterState({
784
+ select: state => {
785
+ let matches = state.pendingMatches?.some(d => d.showPending) ? state.pendingMatches : state.matches;
786
+ matches = matches.slice(matches.findIndex(d => d.id === contextMatches[0]?.id));
787
+ return opts?.select ? opts.select(matches) : matches;
788
+ }
789
+ });
758
790
  }
759
791
  function useLoaderData(opts) {
760
- return useMatch(opts)?.loaderData;
792
+ const match = useMatch({
793
+ ...opts,
794
+ select: undefined
795
+ });
796
+ return typeof opts.select === 'function' ? opts.select(match?.loaderData) : match?.loaderData;
761
797
  }
762
798
 
763
799
  const routerContext = /*#__PURE__*/React.createContext(null);
@@ -788,31 +824,29 @@ function RouterProvider({
788
824
  function RouterProviderInner({
789
825
  router
790
826
  }) {
791
- const [preState, setState] = React.useState(() => router.state);
792
827
  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
828
  router.startReactTransition = startReactTransition;
829
+ React.useEffect(() => {
830
+ if (isTransitioning) {
831
+ router.__store.setState(s => ({
832
+ ...s,
833
+ isTransitioning
834
+ }));
835
+ }
836
+ }, [isTransitioning]);
803
837
  const tryLoad = () => {
804
- startReactTransition(() => {
805
- try {
806
- router.load();
807
- } catch (err) {
808
- console.error(err);
809
- }
810
- });
838
+ // startReactTransition(() => {
839
+ try {
840
+ router.load();
841
+ } catch (err) {
842
+ console.error(err);
843
+ }
844
+ // })
811
845
  };
812
846
  useLayoutEffect$1(() => {
813
847
  const unsub = router.history.subscribe(() => {
814
848
  router.latestLocation = router.parseLocation(router.latestLocation);
815
- if (state.location !== router.latestLocation) {
849
+ if (router.state.location !== router.latestLocation) {
816
850
  tryLoad();
817
851
  }
818
852
  });
@@ -822,7 +856,7 @@ function RouterProviderInner({
822
856
  hash: true,
823
857
  state: true
824
858
  });
825
- if (state.location.href !== nextLocation.href) {
859
+ if (router.state.location.href !== nextLocation.href) {
826
860
  router.commitLocation({
827
861
  ...nextLocation,
828
862
  replace: true
@@ -833,20 +867,21 @@ function RouterProviderInner({
833
867
  };
834
868
  }, [router.history]);
835
869
  useLayoutEffect$1(() => {
836
- if (!isTransitioning && state.resolvedLocation !== state.location) {
870
+ if (!isTransitioning && router.state.resolvedLocation !== router.state.location) {
837
871
  router.emit({
838
872
  type: 'onResolved',
839
- fromLocation: state.resolvedLocation,
840
- toLocation: state.location,
841
- pathChanged: state.location.href !== state.resolvedLocation?.href
873
+ fromLocation: router.state.resolvedLocation,
874
+ toLocation: router.state.location,
875
+ pathChanged: router.state.location.href !== router.state.resolvedLocation?.href
842
876
  });
843
877
  router.pendingMatches = [];
844
- setState(s => ({
878
+ router.__store.setState(s => ({
845
879
  ...s,
880
+ isTransitioning: false,
846
881
  resolvedLocation: s.location
847
882
  }));
848
883
  }
849
- });
884
+ }, [isTransitioning]);
850
885
  useLayoutEffect$1(() => {
851
886
  if (!window.__TSR_DEHYDRATED__) {
852
887
  tryLoad();
@@ -857,7 +892,11 @@ function RouterProviderInner({
857
892
  }, /*#__PURE__*/React.createElement(Matches, null));
858
893
  }
859
894
  function getRouteMatch(state, id) {
860
- return [...state.pendingMatches, ...state.matches].find(d => d.id === id);
895
+ return [...(state.pendingMatches ?? []), ...state.matches].find(d => d.id === id);
896
+ }
897
+ function useRouterState(opts) {
898
+ const router = useRouter();
899
+ return useStore(router.__store, opts?.select);
861
900
  }
862
901
  function useRouter() {
863
902
  const resolvedContext = typeof document !== 'undefined' ? window.__TSR_ROUTER_CONTEXT__ || routerContext : routerContext;
@@ -1220,9 +1259,6 @@ class Router {
1220
1259
  // by the router provider once rendered. We provide these so that the
1221
1260
  // router can be used in a non-react environment if necessary
1222
1261
  startReactTransition = fn => fn();
1223
- setState = updater => {
1224
- this.state = functionalUpdate(updater, this.state);
1225
- };
1226
1262
  update = newOptions => {
1227
1263
  this.options = {
1228
1264
  ...this.options,
@@ -1237,10 +1273,20 @@ class Router {
1237
1273
  this.routeTree = this.options.routeTree;
1238
1274
  this.buildRouteTree();
1239
1275
  }
1240
- if (!this.state) {
1241
- this.state = getInitialRouterState(this.latestLocation);
1276
+ if (!this.__store) {
1277
+ this.__store = new Store(getInitialRouterState(this.latestLocation), {
1278
+ onUpdate: () => {
1279
+ this.__store.state = {
1280
+ ...this.state,
1281
+ status: this.state.isTransitioning || this.state.isLoading ? 'pending' : 'idle'
1282
+ };
1283
+ }
1284
+ });
1242
1285
  }
1243
1286
  };
1287
+ get state() {
1288
+ return this.__store.state;
1289
+ }
1244
1290
  buildRouteTree = () => {
1245
1291
  this.routesById = {};
1246
1292
  this.routesByPath = {};
@@ -1512,7 +1558,7 @@ class Router {
1512
1558
  getRouteMatch(this.state, id)?.abortController?.abort();
1513
1559
  };
1514
1560
  cancelMatches = () => {
1515
- this.state.matches.forEach(match => {
1561
+ this.state.pendingMatches?.forEach(match => {
1516
1562
  this.cancelMatch(match.id);
1517
1563
  });
1518
1564
  };
@@ -1703,6 +1749,12 @@ class Router {
1703
1749
  }) => {
1704
1750
  let latestPromise;
1705
1751
  let firstBadMatchIndex;
1752
+ const updatePendingMatch = match => {
1753
+ this.__store.setState(s => ({
1754
+ ...s,
1755
+ pendingMatches: s.pendingMatches?.map(d => d.id === match.id ? match : d)
1756
+ }));
1757
+ };
1706
1758
 
1707
1759
  // Check each match middleware to see if the route can be accessed
1708
1760
  try {
@@ -1859,12 +1911,10 @@ class Router {
1859
1911
  loadPromise
1860
1912
  };
1861
1913
  if (!preload) {
1862
- this.setState(s => ({
1863
- ...s,
1864
- matches: s.matches.map(d => d.id === match.id ? match : d)
1865
- }));
1914
+ updatePendingMatch(match);
1866
1915
  }
1867
1916
  let didShowPending = false;
1917
+ const pendingMinMs = route.options.pendingMinMs ?? this.options.defaultPendingMinMs;
1868
1918
  await new Promise(async resolve => {
1869
1919
  // If the route has a pending component and a pendingMs option,
1870
1920
  // forcefully show the pending component
@@ -1876,17 +1926,13 @@ class Router {
1876
1926
  ...match,
1877
1927
  showPending: true
1878
1928
  };
1879
- this.setState(s => ({
1880
- ...s,
1881
- matches: s.matches.map(d => d.id === match.id ? match : d)
1882
- }));
1929
+ updatePendingMatch(match);
1883
1930
  resolve();
1884
1931
  });
1885
1932
  }
1886
1933
  try {
1887
1934
  const loaderData = await loadPromise;
1888
1935
  if (latestPromise = checkLatest()) return await latestPromise;
1889
- const pendingMinMs = route.options.pendingMinMs ?? this.options.defaultPendingMinMs;
1890
1936
  if (didShowPending && pendingMinMs) {
1891
1937
  await new Promise(r => setTimeout(r, pendingMinMs));
1892
1938
  }
@@ -1916,12 +1962,19 @@ class Router {
1916
1962
  isFetching: false,
1917
1963
  updatedAt: Date.now()
1918
1964
  };
1965
+ } finally {
1966
+ // If we showed the pending component, that means
1967
+ // we already moved the pendingMatches to the matches
1968
+ // state, so we need to update that specific match
1969
+ if (didShowPending && pendingMinMs && match.showPending) {
1970
+ this.__store.setState(s => ({
1971
+ ...s,
1972
+ matches: s.matches?.map(d => d.id === match.id ? match : d)
1973
+ }));
1974
+ }
1919
1975
  }
1920
1976
  if (!preload) {
1921
- this.setState(s => ({
1922
- ...s,
1923
- matches: s.matches.map(d => d.id === match.id ? match : d)
1924
- }));
1977
+ updatePendingMatch(match);
1925
1978
  }
1926
1979
  resolve();
1927
1980
  });
@@ -1950,24 +2003,23 @@ class Router {
1950
2003
  });
1951
2004
 
1952
2005
  // Match the routes
1953
- let matches = this.matchRoutes(next.pathname, next.search, {
2006
+ let pendingMatches = this.matchRoutes(next.pathname, next.search, {
1954
2007
  debug: true
1955
2008
  });
1956
- this.pendingMatches = matches;
1957
2009
  const previousMatches = this.state.matches;
1958
2010
 
1959
2011
  // Ingest the new matches
1960
- this.setState(s => ({
2012
+ this.__store.setState(s => ({
1961
2013
  ...s,
1962
- // status: 'pending',
2014
+ isLoading: true,
1963
2015
  location: next,
1964
- matches
2016
+ pendingMatches
1965
2017
  }));
1966
2018
  try {
1967
2019
  try {
1968
2020
  // Load the matches
1969
2021
  await this.loadMatches({
1970
- matches,
2022
+ matches: pendingMatches,
1971
2023
  checkLatest: () => this.checkLatest(promise),
1972
2024
  invalidate: opts?.invalidate
1973
2025
  });
@@ -1982,14 +2034,13 @@ class Router {
1982
2034
  }
1983
2035
  const exitingMatchIds = previousMatches.filter(id => !this.pendingMatches.includes(id));
1984
2036
  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
- // }))
2037
+ const stayingMatchIds = previousMatches.filter(id => this.pendingMatches.includes(id));
2038
+ this.__store.setState(s => ({
2039
+ ...s,
2040
+ isLoading: false,
2041
+ matches: pendingMatches,
2042
+ pendingMatches: undefined
2043
+ }))
1993
2044
 
1994
2045
  //
1995
2046
  ;
@@ -2144,9 +2195,6 @@ class Router {
2144
2195
  return false;
2145
2196
  }
2146
2197
  const baseLocation = opts?.pending ? this.latestLocation : this.state.resolvedLocation;
2147
-
2148
- // const baseLocation = state.resolvedLocation
2149
-
2150
2198
  if (!baseLocation) {
2151
2199
  return false;
2152
2200
  }
@@ -2218,7 +2266,7 @@ class Router {
2218
2266
  }
2219
2267
  return match;
2220
2268
  });
2221
- this.setState(s => {
2269
+ this.__store.setState(s => {
2222
2270
  return {
2223
2271
  ...s,
2224
2272
  matches: matches
@@ -2249,6 +2297,8 @@ class SearchParamError extends Error {}
2249
2297
  class PathParamError extends Error {}
2250
2298
  function getInitialRouterState(location) {
2251
2299
  return {
2300
+ isLoading: false,
2301
+ isTransitioning: false,
2252
2302
  status: 'idle',
2253
2303
  resolvedLocation: location,
2254
2304
  location,
@@ -2480,5 +2530,5 @@ function Navigate(props) {
2480
2530
  return null;
2481
2531
  }
2482
2532
 
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 };
2533
+ 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
2534
  //# sourceMappingURL=index.js.map