@tanstack/react-router 1.53.1 → 1.56.1
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/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +2 -2
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/RouterProvider.d.cts +2 -2
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +10 -1
- package/dist/cjs/index.d.cts +3 -3
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +22 -21
- package/dist/cjs/redirects.cjs.map +1 -1
- package/dist/cjs/redirects.d.cts +2 -2
- package/dist/cjs/route.cjs +18 -2
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +8 -5
- package/dist/cjs/routeInfo.d.cts +32 -21
- package/dist/cjs/router.cjs +4 -1
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +2 -2
- package/dist/cjs/useLoaderData.cjs.map +1 -1
- package/dist/cjs/useLoaderData.d.cts +3 -3
- package/dist/cjs/useLoaderDeps.cjs.map +1 -1
- package/dist/cjs/useLoaderDeps.d.cts +2 -2
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useMatch.d.cts +2 -2
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useNavigate.d.cts +2 -2
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/cjs/useParams.d.cts +2 -2
- package/dist/cjs/useRouteContext.cjs.map +1 -1
- package/dist/cjs/useRouteContext.d.cts +2 -2
- package/dist/cjs/useSearch.cjs.map +1 -1
- package/dist/cjs/useSearch.d.cts +2 -2
- package/dist/esm/Matches.d.ts +2 -2
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.d.ts +2 -2
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +10 -1
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/link.d.ts +22 -21
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/redirects.d.ts +2 -2
- package/dist/esm/redirects.js.map +1 -1
- package/dist/esm/route.d.ts +8 -5
- package/dist/esm/route.js +18 -2
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +32 -21
- package/dist/esm/router.d.ts +2 -2
- package/dist/esm/router.js +4 -1
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/useLoaderData.d.ts +3 -3
- package/dist/esm/useLoaderData.js.map +1 -1
- package/dist/esm/useLoaderDeps.d.ts +2 -2
- package/dist/esm/useLoaderDeps.js.map +1 -1
- package/dist/esm/useMatch.d.ts +2 -2
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useNavigate.d.ts +2 -2
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useParams.d.ts +2 -2
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.d.ts +2 -2
- package/dist/esm/useRouteContext.js.map +1 -1
- package/dist/esm/useSearch.d.ts +2 -2
- package/dist/esm/useSearch.js.map +1 -1
- package/package.json +1 -1
- package/src/Matches.tsx +15 -22
- package/src/RouterProvider.tsx +4 -4
- package/src/fileRoute.ts +25 -1
- package/src/index.tsx +10 -1
- package/src/link.tsx +81 -76
- package/src/redirects.ts +8 -8
- package/src/route.ts +98 -9
- package/src/routeInfo.ts +116 -38
- package/src/router.ts +9 -5
- package/src/useLoaderData.tsx +3 -3
- package/src/useLoaderDeps.tsx +3 -3
- package/src/useMatch.tsx +9 -3
- package/src/useNavigate.tsx +5 -5
- package/src/useParams.tsx +10 -3
- package/src/useRouteContext.ts +8 -3
- package/src/useSearch.tsx +11 -4
package/src/router.ts
CHANGED
|
@@ -1336,7 +1336,8 @@ export class Router<
|
|
|
1336
1336
|
|
|
1337
1337
|
const fromRouteByFromPathRouteId =
|
|
1338
1338
|
this.routesById[
|
|
1339
|
-
stayingMatches?.find((d) => d.pathname === fromPath)
|
|
1339
|
+
stayingMatches?.find((d) => d.pathname === fromPath)
|
|
1340
|
+
?.routeId as keyof this['routesById']
|
|
1340
1341
|
]
|
|
1341
1342
|
|
|
1342
1343
|
let pathname = dest.to
|
|
@@ -1634,7 +1635,7 @@ export class Router<
|
|
|
1634
1635
|
|
|
1635
1636
|
return this.buildAndCommitLocation({
|
|
1636
1637
|
...rest,
|
|
1637
|
-
to,
|
|
1638
|
+
to: to as string,
|
|
1638
1639
|
// to: toString,
|
|
1639
1640
|
})
|
|
1640
1641
|
}
|
|
@@ -2447,7 +2448,7 @@ export class Router<
|
|
|
2447
2448
|
|
|
2448
2449
|
preloadRoute = async <
|
|
2449
2450
|
TFrom extends RoutePaths<TRouteTree> | string = string,
|
|
2450
|
-
TTo extends string =
|
|
2451
|
+
TTo extends string | undefined = undefined,
|
|
2451
2452
|
TMaskFrom extends RoutePaths<TRouteTree> | string = TFrom,
|
|
2452
2453
|
TMaskTo extends string = '',
|
|
2453
2454
|
>(
|
|
@@ -2521,7 +2522,7 @@ export class Router<
|
|
|
2521
2522
|
|
|
2522
2523
|
matchRoute = <
|
|
2523
2524
|
TFrom extends RoutePaths<TRouteTree> = '/',
|
|
2524
|
-
TTo extends string =
|
|
2525
|
+
TTo extends string | undefined = undefined,
|
|
2525
2526
|
TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>,
|
|
2526
2527
|
>(
|
|
2527
2528
|
location: ToOptions<
|
|
@@ -2534,7 +2535,10 @@ export class Router<
|
|
|
2534
2535
|
const matchLocation = {
|
|
2535
2536
|
...location,
|
|
2536
2537
|
to: location.to
|
|
2537
|
-
? this.resolvePathWithBase(
|
|
2538
|
+
? this.resolvePathWithBase(
|
|
2539
|
+
(location.from || '') as string,
|
|
2540
|
+
location.to as string,
|
|
2541
|
+
)
|
|
2538
2542
|
: undefined,
|
|
2539
2543
|
params: location.params || {},
|
|
2540
2544
|
leaveParams: true,
|
package/src/useLoaderData.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import type { RegisteredRouter } from './router'
|
|
|
3
3
|
import type { AnyRoute } from './route'
|
|
4
4
|
import type { MakeRouteMatch } from './Matches'
|
|
5
5
|
import type { RouteIds } from './routeInfo'
|
|
6
|
-
import type { StrictOrFrom } from './utils'
|
|
6
|
+
import type { Constrain, StrictOrFrom } from './utils'
|
|
7
7
|
|
|
8
8
|
export type UseLoaderDataOptions<
|
|
9
9
|
TRouteTree extends AnyRoute,
|
|
@@ -11,13 +11,13 @@ export type UseLoaderDataOptions<
|
|
|
11
11
|
TStrict extends boolean,
|
|
12
12
|
TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom, TStrict>,
|
|
13
13
|
TSelected,
|
|
14
|
-
> = StrictOrFrom<TFrom, TStrict> & {
|
|
14
|
+
> = StrictOrFrom<Constrain<TFrom, RouteIds<TRouteTree>>, TStrict> & {
|
|
15
15
|
select?: (match: Required<TRouteMatch>['loaderData']) => TSelected
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export function useLoaderData<
|
|
19
19
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
20
|
-
TFrom extends
|
|
20
|
+
TFrom extends string | undefined = undefined,
|
|
21
21
|
TStrict extends boolean = true,
|
|
22
22
|
TRouteMatch extends MakeRouteMatch<
|
|
23
23
|
TRouteTree,
|
package/src/useLoaderDeps.tsx
CHANGED
|
@@ -3,18 +3,18 @@ import type { RegisteredRouter } from './router'
|
|
|
3
3
|
import type { AnyRoute } from './route'
|
|
4
4
|
import type { MakeRouteMatch } from './Matches'
|
|
5
5
|
import type { RouteIds } from './routeInfo'
|
|
6
|
-
import type { StrictOrFrom } from './utils'
|
|
6
|
+
import type { Constrain, StrictOrFrom } from './utils'
|
|
7
7
|
|
|
8
8
|
export function useLoaderDeps<
|
|
9
9
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
10
|
-
TFrom extends
|
|
10
|
+
TFrom extends string | undefined = undefined,
|
|
11
11
|
TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom> = MakeRouteMatch<
|
|
12
12
|
TRouteTree,
|
|
13
13
|
TFrom
|
|
14
14
|
>,
|
|
15
15
|
TSelected = Required<TRouteMatch>['loaderDeps'],
|
|
16
16
|
>(
|
|
17
|
-
opts: StrictOrFrom<TFrom
|
|
17
|
+
opts: StrictOrFrom<Constrain<TFrom, RouteIds<TRouteTree>>> & {
|
|
18
18
|
select?: (match: TRouteMatch) => TSelected
|
|
19
19
|
},
|
|
20
20
|
): TSelected {
|
package/src/useMatch.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import type { RegisteredRouter } from './router'
|
|
|
6
6
|
import type { AnyRoute } from './route'
|
|
7
7
|
import type { MakeRouteMatch } from './Matches'
|
|
8
8
|
import type { RouteIds } from './routeInfo'
|
|
9
|
-
import type { StrictOrFrom } from './utils'
|
|
9
|
+
import type { Constrain, StrictOrFrom } from './utils'
|
|
10
10
|
|
|
11
11
|
export type UseMatchOptions<
|
|
12
12
|
TFrom,
|
|
@@ -21,13 +21,19 @@ export type UseMatchOptions<
|
|
|
21
21
|
|
|
22
22
|
export function useMatch<
|
|
23
23
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
24
|
-
TFrom extends
|
|
24
|
+
TFrom extends string | undefined = undefined,
|
|
25
25
|
TStrict extends boolean = true,
|
|
26
26
|
TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>,
|
|
27
27
|
TSelected = TRouteMatch,
|
|
28
28
|
TThrow extends boolean = true,
|
|
29
29
|
>(
|
|
30
|
-
opts: UseMatchOptions<
|
|
30
|
+
opts: UseMatchOptions<
|
|
31
|
+
Constrain<TFrom, RouteIds<TRouteTree>>,
|
|
32
|
+
TStrict,
|
|
33
|
+
TRouteMatch,
|
|
34
|
+
TSelected,
|
|
35
|
+
TThrow
|
|
36
|
+
>,
|
|
31
37
|
): TThrow extends true ? TSelected : TSelected | undefined {
|
|
32
38
|
const nearestMatchId = React.useContext(matchContext)
|
|
33
39
|
|
package/src/useNavigate.tsx
CHANGED
|
@@ -5,10 +5,10 @@ import type { RoutePaths } from './routeInfo'
|
|
|
5
5
|
import type { AnyRouter, RegisteredRouter } from './router'
|
|
6
6
|
|
|
7
7
|
export type UseNavigateResult<TDefaultFrom extends string> = <
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
TFrom extends
|
|
11
|
-
TMaskFrom extends
|
|
8
|
+
TRouter extends RegisteredRouter,
|
|
9
|
+
TTo extends string | undefined,
|
|
10
|
+
TFrom extends string = TDefaultFrom,
|
|
11
|
+
TMaskFrom extends string = TFrom,
|
|
12
12
|
TMaskTo extends string = '',
|
|
13
13
|
>({
|
|
14
14
|
from,
|
|
@@ -51,7 +51,7 @@ export function useNavigate<
|
|
|
51
51
|
export function Navigate<
|
|
52
52
|
TRouter extends AnyRouter = RegisteredRouter,
|
|
53
53
|
TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
|
|
54
|
-
TTo extends string =
|
|
54
|
+
TTo extends string | undefined = undefined,
|
|
55
55
|
TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
|
|
56
56
|
TMaskTo extends string = '',
|
|
57
57
|
>(props: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): null {
|
package/src/useParams.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { useMatch } from './useMatch'
|
|
|
2
2
|
import type { AnyRoute } from './route'
|
|
3
3
|
import type { AllParams, RouteById, RouteIds } from './routeInfo'
|
|
4
4
|
import type { RegisteredRouter } from './router'
|
|
5
|
-
import type { StrictOrFrom } from './utils'
|
|
5
|
+
import type { Constrain, StrictOrFrom } from './utils'
|
|
6
6
|
|
|
7
7
|
export type UseParamsOptions<
|
|
8
8
|
TFrom,
|
|
@@ -15,13 +15,20 @@ export type UseParamsOptions<
|
|
|
15
15
|
|
|
16
16
|
export function useParams<
|
|
17
17
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
18
|
-
TFrom extends
|
|
18
|
+
TFrom extends string | undefined = undefined,
|
|
19
19
|
TStrict extends boolean = true,
|
|
20
20
|
TParams = TStrict extends false
|
|
21
21
|
? AllParams<TRouteTree>
|
|
22
22
|
: RouteById<TRouteTree, TFrom>['types']['allParams'],
|
|
23
23
|
TSelected = TParams,
|
|
24
|
-
>(
|
|
24
|
+
>(
|
|
25
|
+
opts: UseParamsOptions<
|
|
26
|
+
Constrain<TFrom, RouteIds<TRouteTree>>,
|
|
27
|
+
TStrict,
|
|
28
|
+
TParams,
|
|
29
|
+
TSelected
|
|
30
|
+
>,
|
|
31
|
+
): TSelected {
|
|
25
32
|
return useMatch({
|
|
26
33
|
...opts,
|
|
27
34
|
select: (match) => {
|
package/src/useRouteContext.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { MakeRouteMatch } from './Matches'
|
|
|
3
3
|
import type { AnyRoute } from './route'
|
|
4
4
|
import type { AllContext, RouteById, RouteIds } from './routeInfo'
|
|
5
5
|
import type { RegisteredRouter } from './router'
|
|
6
|
-
import type { Expand, StrictOrFrom } from './utils'
|
|
6
|
+
import type { Constrain, Expand, StrictOrFrom } from './utils'
|
|
7
7
|
|
|
8
8
|
export type UseRouteContextOptions<
|
|
9
9
|
TFrom,
|
|
@@ -16,14 +16,19 @@ export type UseRouteContextOptions<
|
|
|
16
16
|
|
|
17
17
|
export function useRouteContext<
|
|
18
18
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
19
|
-
TFrom extends
|
|
19
|
+
TFrom extends string | undefined = undefined,
|
|
20
20
|
TStrict extends boolean = true,
|
|
21
21
|
TRouteContext = TStrict extends false
|
|
22
22
|
? AllContext<TRouteTree>
|
|
23
23
|
: Expand<RouteById<TRouteTree, TFrom>['types']['allContext']>,
|
|
24
24
|
TSelected = TRouteContext,
|
|
25
25
|
>(
|
|
26
|
-
opts: UseRouteContextOptions<
|
|
26
|
+
opts: UseRouteContextOptions<
|
|
27
|
+
Constrain<TFrom, RouteIds<TRouteTree>>,
|
|
28
|
+
TStrict,
|
|
29
|
+
TRouteContext,
|
|
30
|
+
TSelected
|
|
31
|
+
>,
|
|
27
32
|
): TSelected {
|
|
28
33
|
return useMatch({
|
|
29
34
|
...(opts as any),
|
package/src/useSearch.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import type { AnyRoute } from './route'
|
|
|
3
3
|
import type { FullSearchSchema, RouteById, RouteIds } from './routeInfo'
|
|
4
4
|
import type { RegisteredRouter } from './router'
|
|
5
5
|
import type { MakeRouteMatch } from './Matches'
|
|
6
|
-
import type { Expand, StrictOrFrom } from './utils'
|
|
6
|
+
import type { Constrain, Expand, StrictOrFrom } from './utils'
|
|
7
7
|
|
|
8
8
|
export type UseSearchOptions<
|
|
9
9
|
TFrom,
|
|
@@ -16,16 +16,23 @@ export type UseSearchOptions<
|
|
|
16
16
|
|
|
17
17
|
export function useSearch<
|
|
18
18
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
19
|
-
TFrom extends
|
|
19
|
+
TFrom extends string | undefined = undefined,
|
|
20
20
|
TStrict extends boolean = true,
|
|
21
21
|
TSearch = TStrict extends false
|
|
22
22
|
? FullSearchSchema<TRouteTree>
|
|
23
23
|
: Expand<RouteById<TRouteTree, TFrom>['types']['fullSearchSchema']>,
|
|
24
24
|
TSelected = TSearch,
|
|
25
|
-
>(
|
|
25
|
+
>(
|
|
26
|
+
opts: UseSearchOptions<
|
|
27
|
+
Constrain<TFrom, RouteIds<TRouteTree>>,
|
|
28
|
+
TStrict,
|
|
29
|
+
TSearch,
|
|
30
|
+
TSelected
|
|
31
|
+
>,
|
|
32
|
+
): TSelected {
|
|
26
33
|
return useMatch({
|
|
27
34
|
...opts,
|
|
28
|
-
select: (match
|
|
35
|
+
select: (match) => {
|
|
29
36
|
return opts.select ? opts.select(match.search) : match.search
|
|
30
37
|
},
|
|
31
38
|
})
|