@tanstack/react-router 1.0.1 → 1.0.2
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/build/cjs/link.js +4 -1
- package/build/cjs/link.js.map +1 -1
- package/build/cjs/router.js +5 -4
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/useNavigate.js +9 -6
- package/build/cjs/useNavigate.js.map +1 -1
- package/build/esm/index.js +18 -11
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +355 -355
- package/build/types/link.d.ts +1 -1
- package/build/types/useNavigate.d.ts +2 -2
- package/build/umd/index.development.js +18 -11
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/link.tsx +13 -7
- package/src/router.ts +5 -4
- package/src/useNavigate.tsx +10 -8
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@tanstack/store": "^0.1.3",
|
|
45
45
|
"tiny-invariant": "^1.3.1",
|
|
46
46
|
"tiny-warning": "^1.0.3",
|
|
47
|
-
"@tanstack/history": "1.0.
|
|
47
|
+
"@tanstack/history": "1.0.2"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rollup --config rollup.config.js"
|
package/src/link.tsx
CHANGED
|
@@ -172,9 +172,9 @@ export type SearchParamOptions<
|
|
|
172
172
|
TFromSearchEnsured = '/' extends TFrom
|
|
173
173
|
? FullSearchSchema<TRouteTree>
|
|
174
174
|
: Expand<
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
PickRequired<
|
|
176
|
+
RouteByPath<TRouteTree, TFrom>['types']['fullSearchSchema']
|
|
177
|
+
>
|
|
178
178
|
>,
|
|
179
179
|
TFromSearchOptional = Omit<
|
|
180
180
|
FullSearchSchema<TRouteTree>,
|
|
@@ -352,9 +352,16 @@ export function useLinkProps<
|
|
|
352
352
|
TTo extends string = '',
|
|
353
353
|
TMaskFrom extends RoutePaths<TRouteTree> = '/',
|
|
354
354
|
TMaskTo extends string = '',
|
|
355
|
-
>(
|
|
356
|
-
|
|
357
|
-
|
|
355
|
+
>({
|
|
356
|
+
from,
|
|
357
|
+
...options
|
|
358
|
+
}: UseLinkPropsOptions<
|
|
359
|
+
TRouteTree,
|
|
360
|
+
TFrom,
|
|
361
|
+
TTo,
|
|
362
|
+
TMaskFrom,
|
|
363
|
+
TMaskTo
|
|
364
|
+
>): React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
358
365
|
const router = useRouter()
|
|
359
366
|
const matchPathname = useMatch({
|
|
360
367
|
strict: false,
|
|
@@ -416,7 +423,6 @@ export function useLinkProps<
|
|
|
416
423
|
}
|
|
417
424
|
|
|
418
425
|
const next = router.buildLocation(dest as any)
|
|
419
|
-
|
|
420
426
|
const preload = userPreload ?? router.options.defaultPreload
|
|
421
427
|
const preloadDelay =
|
|
422
428
|
userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0
|
package/src/router.ts
CHANGED
|
@@ -945,14 +945,14 @@ export class Router<
|
|
|
945
945
|
})
|
|
946
946
|
}
|
|
947
947
|
|
|
948
|
-
navigate: NavigateFn<TRouteTree> = ({ from, to
|
|
948
|
+
navigate: NavigateFn<TRouteTree> = ({ from, to, ...rest }) => {
|
|
949
949
|
// If this link simply reloads the current route,
|
|
950
950
|
// make sure it has a new key so it will trigger a data refresh
|
|
951
951
|
|
|
952
952
|
// If this `to` is a valid external URL, return
|
|
953
953
|
// null for LinkUtils
|
|
954
954
|
const toString = String(to)
|
|
955
|
-
const fromString =
|
|
955
|
+
// const fromString = from !== undefined ? String(from) : from
|
|
956
956
|
let isExternal
|
|
957
957
|
|
|
958
958
|
try {
|
|
@@ -967,8 +967,9 @@ export class Router<
|
|
|
967
967
|
|
|
968
968
|
return this.buildAndCommitLocation({
|
|
969
969
|
...rest,
|
|
970
|
-
from
|
|
971
|
-
to
|
|
970
|
+
from,
|
|
971
|
+
to,
|
|
972
|
+
// to: toString,
|
|
972
973
|
})
|
|
973
974
|
}
|
|
974
975
|
|
package/src/useNavigate.tsx
CHANGED
|
@@ -10,25 +10,27 @@ import { useLayoutEffect } from './utils'
|
|
|
10
10
|
export function useNavigate<
|
|
11
11
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
12
12
|
TDefaultFrom extends RoutePaths<TRouteTree> = '/',
|
|
13
|
-
>(
|
|
14
|
-
const { navigate } = useRouter()
|
|
13
|
+
>(_defaultOpts?: { from?: TDefaultFrom }) {
|
|
14
|
+
const { navigate, buildLocation } = useRouter()
|
|
15
|
+
|
|
15
16
|
const matchPathname = useMatch({
|
|
16
17
|
strict: false,
|
|
17
18
|
select: (s) => s.pathname,
|
|
18
19
|
})
|
|
20
|
+
|
|
19
21
|
return React.useCallback(
|
|
20
22
|
<
|
|
21
23
|
TFrom extends RoutePaths<TRouteTree> = TDefaultFrom,
|
|
22
24
|
TTo extends string = '',
|
|
23
25
|
TMaskFrom extends RoutePaths<TRouteTree> = '/',
|
|
24
26
|
TMaskTo extends string = '',
|
|
25
|
-
>(
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
>({
|
|
28
|
+
from,
|
|
29
|
+
...rest
|
|
30
|
+
}: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => {
|
|
28
31
|
return navigate({
|
|
29
|
-
from:
|
|
30
|
-
...
|
|
31
|
-
...(opts as any),
|
|
32
|
+
from: rest?.to ? matchPathname : undefined,
|
|
33
|
+
...(rest as any),
|
|
32
34
|
})
|
|
33
35
|
},
|
|
34
36
|
[],
|