@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/dist/cjs/awaited.cjs.map +1 -1
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/link.cjs +3 -3
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +1 -1
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +2 -2
- package/dist/cjs/utils.cjs +11 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +2 -0
- package/dist/esm/awaited.js.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/link.d.ts +1 -1
- package/dist/esm/link.js +4 -4
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/router.d.ts +2 -2
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/utils.d.ts +2 -0
- package/dist/esm/utils.js +11 -0
- package/dist/esm/utils.js.map +1 -1
- package/package.json +5 -5
- package/src/awaited.tsx +1 -1
- package/src/link.tsx +4 -4
- package/src/router.ts +2 -2
- package/src/utils.ts +15 -0
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
|
|
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
|
|
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.
|
|
143
|
-
InnerWrap?: (props: { children: any }) => React.
|
|
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
|
+
}
|