@tanstack/react-router 1.22.7 → 1.22.9

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
@@ -2,7 +2,7 @@ import * as React from 'react'
2
2
  import { useMatch } from './Matches'
3
3
  import { useRouterState } from './useRouterState'
4
4
  import { useRouter } from './useRouter'
5
- import { deepEqual, functionalUpdate } from './utils'
5
+ import { deepEqual, exactPathTest, functionalUpdate } from './utils'
6
6
  import type { HistoryState } from '@tanstack/history'
7
7
  import type { Trim } from './fileRoute'
8
8
  import type { AnyRoute, RootSearchSchema } from './route'
@@ -435,7 +435,7 @@ export function useLinkProps<
435
435
  )
436
436
  // Combine the matches based on user router.options
437
437
  const pathTest = activeOptions?.exact
438
- ? s.location.pathname === next.pathname
438
+ ? exactPathTest(s.location.pathname, next.pathname)
439
439
  : pathIsFuzzyEqual
440
440
  const hashTest = activeOptions?.includeHash
441
441
  ? s.location.hash === next.hash
@@ -625,7 +625,7 @@ export type LinkProps<
625
625
  | ((state: { isActive: boolean }) => React.ReactNode)
626
626
  }
627
627
 
628
- type LinkComponent<TComp> = <
628
+ export type LinkComponent<TComp> = <
629
629
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
630
630
  TFrom extends RoutePaths<TRouteTree> | string = string,
631
631
  TTo extends string = '',
@@ -652,7 +652,7 @@ type LinkComponent<TComp> = <
652
652
  ) => React.ReactElement
653
653
 
654
654
  export function createLink<const TComp>(Comp: TComp): LinkComponent<TComp> {
655
- return React.forwardRef(function Link(props, ref) {
655
+ return React.forwardRef(function CreatedLink(props, ref) {
656
656
  return <Link {...(props as any)} _asChild={Comp} ref={ref} />
657
657
  }) as any
658
658
  }
package/src/router.ts CHANGED
@@ -139,8 +139,8 @@ export interface RouterOptions<
139
139
  hydrate?: (dehydrated: TDehydrated) => void
140
140
  routeMasks?: Array<RouteMask<TRouteTree>>
141
141
  unmaskOnReload?: boolean
142
- Wrap?: (props: { children: any }) => React.ReactNode
143
- InnerWrap?: (props: { children: any }) => React.ReactNode
142
+ Wrap?: (props: { children: any }) => React.JSX.Element
143
+ InnerWrap?: (props: { children: any }) => React.JSX.Element
144
144
  /**
145
145
  * @deprecated
146
146
  * Use `notFoundComponent` instead.
package/src/utils.ts CHANGED
@@ -348,3 +348,18 @@ export function escapeJSON(jsonString: string) {
348
348
  .replace(/'/g, "\\'") // Escape single quotes
349
349
  .replace(/"/g, '\\"') // Escape double quotes
350
350
  }
351
+
352
+ export function removeTrailingSlash(value: string): string {
353
+ if (value.endsWith('/') && value !== '/') {
354
+ return value.slice(0, -1)
355
+ }
356
+ return value
357
+ }
358
+
359
+ // intended to only compare path name
360
+ // see the usage in the isActive under useLinkProps
361
+ // /sample/path1 = /sample/path1/
362
+ // /sample/path1/some <> /sample/path1
363
+ export function exactPathTest(pathName1: string, pathName2: string): boolean {
364
+ return removeTrailingSlash(pathName1) === removeTrailingSlash(pathName2)
365
+ }