@tanstack/react-router 1.12.7 → 1.12.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.
package/src/link.tsx CHANGED
@@ -215,11 +215,12 @@ export type ParamOptions<
215
215
  TParamVariant
216
216
  >,
217
217
  TReducer = ParamsReducer<TFromParams, TToParams>,
218
- > = Expand<WithoutEmpty<PickRequired<TToParams>>> extends never
219
- ? Partial<MakeParamOption<TParamVariant, true | TReducer>>
220
- : TFromParams extends Expand<WithoutEmpty<PickRequired<TToParams>>>
221
- ? MakeParamOption<TParamVariant, true | TReducer>
222
- : MakeParamOption<TParamVariant, TReducer>
218
+ > =
219
+ Expand<WithoutEmpty<PickRequired<TToParams>>> extends never
220
+ ? Partial<MakeParamOption<TParamVariant, true | TReducer>>
221
+ : TFromParams extends Expand<WithoutEmpty<PickRequired<TToParams>>>
222
+ ? MakeParamOption<TParamVariant, true | TReducer>
223
+ : MakeParamOption<TParamVariant, TReducer>
223
224
 
224
225
  type MakeParamOption<
225
226
  TParamVariant extends ParamVariant,
@@ -281,12 +282,10 @@ export type LinkOptions<
281
282
  disabled?: boolean
282
283
  }
283
284
 
284
- export type CheckPath<TRouteTree extends AnyRoute, TPath, TPass> = Exclude<
285
- TPath,
286
- RoutePaths<TRouteTree>
287
- > extends never
288
- ? TPass
289
- : CheckPathError<TRouteTree, Exclude<TPath, RoutePaths<TRouteTree>>>
285
+ export type CheckPath<TRouteTree extends AnyRoute, TPath, TPass> =
286
+ Exclude<TPath, RoutePaths<TRouteTree>> extends never
287
+ ? TPass
288
+ : CheckPathError<TRouteTree, Exclude<TPath, RoutePaths<TRouteTree>>>
290
289
 
291
290
  export type CheckPathError<TRouteTree extends AnyRoute, TInvalids> = {
292
291
  to: RoutePaths<TRouteTree>
@@ -555,6 +554,14 @@ export interface LinkComponent<TProps extends Record<string, any> = {}> {
555
554
  }
556
555
 
557
556
  export const Link: LinkComponent = React.forwardRef((props: any, ref) => {
557
+ if (props.href) {
558
+ return <a {...props} ref={ref} />
559
+ }
560
+
561
+ return <InternalLink {...props} ref={ref} />
562
+ })
563
+
564
+ const InternalLink: LinkComponent = React.forwardRef((props: any, ref) => {
558
565
  const linkProps = useLinkProps(props)
559
566
 
560
567
  return (
package/src/router.ts CHANGED
@@ -509,13 +509,14 @@ export class Router<
509
509
  state,
510
510
  }: HistoryLocation): ParsedLocation<FullSearchSchema<TRouteTree>> => {
511
511
  const parsedSearch = this.options.parseSearch(search)
512
+ const searchStr = this.options.stringifySearch(parsedSearch)
512
513
 
513
514
  return {
514
515
  pathname: pathname,
515
- searchStr: search,
516
+ searchStr,
516
517
  search: replaceEqualDeep(previousLocation?.search, parsedSearch) as any,
517
518
  hash: hash.split('#').reverse()[0] ?? '',
518
- href: `${pathname}${search}${hash}`,
519
+ href: `${pathname}${searchStr}${hash}`,
519
520
  state: replaceEqualDeep(previousLocation?.state, state) as HistoryState,
520
521
  }
521
522
  }
@@ -1,11 +1,18 @@
1
1
  import * as React from 'react'
2
2
  import { Router } from './router'
3
3
 
4
- export let routerContext = React.createContext<Router<any>>(null!)
5
- if (typeof document !== 'undefined') {
4
+ let routerContext = React.createContext<Router<any>>(null!)
5
+
6
+ export function getRouterContext() {
7
+ if (typeof document === 'undefined') {
8
+ return routerContext
9
+ }
10
+
6
11
  if (window.__TSR_ROUTER_CONTEXT__) {
7
- routerContext = window.__TSR_ROUTER_CONTEXT__
8
- } else {
9
- window.__TSR_ROUTER_CONTEXT__ = routerContext as any
12
+ return window.__TSR_ROUTER_CONTEXT__
10
13
  }
14
+
15
+ window.__TSR_ROUTER_CONTEXT__ = routerContext as any
16
+
17
+ return routerContext
11
18
  }
package/src/useRouter.tsx CHANGED
@@ -2,16 +2,12 @@ import * as React from 'react'
2
2
  import warning from 'tiny-warning'
3
3
  import { AnyRoute } from './route'
4
4
  import { RegisteredRouter, Router } from './router'
5
- import { routerContext } from './routerContext'
5
+ import { getRouterContext } from './routerContext'
6
6
 
7
7
  export function useRouter<
8
8
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
9
9
  >(opts?: { warn?: boolean }): Router<TRouteTree> {
10
- const resolvedContext =
11
- typeof document !== 'undefined'
12
- ? window.__TSR_ROUTER_CONTEXT__ || routerContext
13
- : routerContext
14
- const value = React.useContext(resolvedContext)
10
+ const value = React.useContext(getRouterContext())
15
11
  warning(
16
12
  !((opts?.warn ?? true) && !value),
17
13
  'useRouter must be used inside a <RouterProvider> component!',