@tanstack/react-router 0.0.1-beta.68 → 0.0.1-beta.69
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/index.js +11 -2
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +11 -3
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +50 -50
- package/build/types/index.d.ts +14 -13
- package/build/umd/index.development.js +37 -18
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +3 -3
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +37 -15
package/src/index.tsx
CHANGED
|
@@ -30,6 +30,8 @@ import {
|
|
|
30
30
|
AnySearchSchema,
|
|
31
31
|
AnyPathParams,
|
|
32
32
|
AnyRouteMatch,
|
|
33
|
+
NavigateOptions,
|
|
34
|
+
RouterConstructorOptions,
|
|
33
35
|
} from '@tanstack/router'
|
|
34
36
|
import { useStore } from '@tanstack/react-store'
|
|
35
37
|
|
|
@@ -68,7 +70,7 @@ export function lazy(
|
|
|
68
70
|
|
|
69
71
|
export type LinkPropsOptions<
|
|
70
72
|
TFrom extends RegisteredRoutesInfo['routePaths'] = '/',
|
|
71
|
-
TTo extends string = '
|
|
73
|
+
TTo extends string = '',
|
|
72
74
|
> = LinkOptions<RegisteredRoutesInfo, TFrom, TTo> & {
|
|
73
75
|
// A function that returns additional props for the `active` state of this link. These props override other props passed to the link (`style`'s are merged, `className`'s are concatenated)
|
|
74
76
|
activeProps?:
|
|
@@ -82,12 +84,12 @@ export type LinkPropsOptions<
|
|
|
82
84
|
|
|
83
85
|
export type MakeUseMatchRouteOptions<
|
|
84
86
|
TFrom extends RegisteredRoutesInfo['routePaths'] = '/',
|
|
85
|
-
TTo extends string = '
|
|
87
|
+
TTo extends string = '',
|
|
86
88
|
> = ToOptions<RegisteredRoutesInfo, TFrom, TTo> & MatchRouteOptions
|
|
87
89
|
|
|
88
90
|
export type MakeMatchRouteOptions<
|
|
89
91
|
TFrom extends RegisteredRoutesInfo['routePaths'] = '/',
|
|
90
|
-
TTo extends string = '
|
|
92
|
+
TTo extends string = '',
|
|
91
93
|
> = ToOptions<RegisteredRoutesInfo, TFrom, TTo> &
|
|
92
94
|
MatchRouteOptions & {
|
|
93
95
|
// If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns
|
|
@@ -103,12 +105,12 @@ export type MakeMatchRouteOptions<
|
|
|
103
105
|
|
|
104
106
|
export type MakeLinkPropsOptions<
|
|
105
107
|
TFrom extends ValidFromPath<RegisteredRoutesInfo> = '/',
|
|
106
|
-
TTo extends string = '
|
|
108
|
+
TTo extends string = '',
|
|
107
109
|
> = LinkPropsOptions<TFrom, TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>
|
|
108
110
|
|
|
109
111
|
export type MakeLinkOptions<
|
|
110
112
|
TFrom extends RegisteredRoutesInfo['routePaths'] = '/',
|
|
111
|
-
TTo extends string = '
|
|
113
|
+
TTo extends string = '',
|
|
112
114
|
> = LinkPropsOptions<TFrom, TTo> &
|
|
113
115
|
React.AnchorHTMLAttributes<HTMLAnchorElement> &
|
|
114
116
|
Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
|
|
@@ -144,7 +146,7 @@ export type PromptProps = {
|
|
|
144
146
|
|
|
145
147
|
export function useLinkProps<
|
|
146
148
|
TFrom extends ValidFromPath<RegisteredRoutesInfo> = '/',
|
|
147
|
-
TTo extends string = '
|
|
149
|
+
TTo extends string = '',
|
|
148
150
|
>(
|
|
149
151
|
options: MakeLinkPropsOptions<TFrom, TTo>,
|
|
150
152
|
): React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
@@ -175,7 +177,6 @@ export function useLinkProps<
|
|
|
175
177
|
onMouseEnter,
|
|
176
178
|
onMouseLeave,
|
|
177
179
|
onTouchStart,
|
|
178
|
-
onTouchEnd,
|
|
179
180
|
...rest
|
|
180
181
|
} = options
|
|
181
182
|
|
|
@@ -186,8 +187,15 @@ export function useLinkProps<
|
|
|
186
187
|
return { href }
|
|
187
188
|
}
|
|
188
189
|
|
|
189
|
-
const {
|
|
190
|
-
|
|
190
|
+
const {
|
|
191
|
+
handleClick,
|
|
192
|
+
handleFocus,
|
|
193
|
+
handleEnter,
|
|
194
|
+
handleLeave,
|
|
195
|
+
handleTouchStart,
|
|
196
|
+
isActive,
|
|
197
|
+
next,
|
|
198
|
+
} = linkInfo
|
|
191
199
|
|
|
192
200
|
const reactHandleClick = (e: Event) => {
|
|
193
201
|
if (React.startTransition) {
|
|
@@ -228,6 +236,7 @@ export function useLinkProps<
|
|
|
228
236
|
onFocus: composeHandlers([onFocus, handleFocus]),
|
|
229
237
|
onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),
|
|
230
238
|
onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),
|
|
239
|
+
onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),
|
|
231
240
|
target,
|
|
232
241
|
style: {
|
|
233
242
|
...style,
|
|
@@ -254,7 +263,7 @@ export function useLinkProps<
|
|
|
254
263
|
|
|
255
264
|
export interface LinkFn<
|
|
256
265
|
TDefaultFrom extends RegisteredRoutesInfo['routePaths'] = '/',
|
|
257
|
-
TDefaultTo extends string = '
|
|
266
|
+
TDefaultTo extends string = '',
|
|
258
267
|
> {
|
|
259
268
|
<
|
|
260
269
|
TFrom extends RegisteredRoutesInfo['routePaths'] = TDefaultFrom,
|
|
@@ -283,6 +292,19 @@ export const Link: LinkFn = React.forwardRef((props: any, ref) => {
|
|
|
283
292
|
)
|
|
284
293
|
}) as any
|
|
285
294
|
|
|
295
|
+
export function Navigate<
|
|
296
|
+
TFrom extends RegisteredRoutesInfo['routePaths'] = '/',
|
|
297
|
+
TTo extends string = '',
|
|
298
|
+
>(props: NavigateOptions<RegisteredRoutesInfo, TFrom, TTo>): null {
|
|
299
|
+
const router = useRouterContext()
|
|
300
|
+
|
|
301
|
+
React.useLayoutEffect(() => {
|
|
302
|
+
router.navigate(props as any)
|
|
303
|
+
}, [])
|
|
304
|
+
|
|
305
|
+
return null
|
|
306
|
+
}
|
|
307
|
+
|
|
286
308
|
type MatchesContextValue = AnyRouteMatch[]
|
|
287
309
|
|
|
288
310
|
export const matchesContext = React.createContext<MatchesContextValue>(null!)
|
|
@@ -299,7 +321,7 @@ export class ReactRouter<
|
|
|
299
321
|
TRouteConfig extends AnyRootRoute = RootRoute,
|
|
300
322
|
TRoutesInfo extends AnyRoutesInfo = RoutesInfo<TRouteConfig>,
|
|
301
323
|
> extends Router<TRouteConfig, TRoutesInfo> {
|
|
302
|
-
constructor(opts:
|
|
324
|
+
constructor(opts: RouterConstructorOptions<TRouteConfig>) {
|
|
303
325
|
super({
|
|
304
326
|
...opts,
|
|
305
327
|
loadComponent: async (component) => {
|
|
@@ -423,7 +445,7 @@ export function useRoute<
|
|
|
423
445
|
resolvedRoute,
|
|
424
446
|
`Could not find a route for route "${
|
|
425
447
|
routeId as string
|
|
426
|
-
}"! Did you forget to add it to your route
|
|
448
|
+
}"! Did you forget to add it to your route?`,
|
|
427
449
|
)
|
|
428
450
|
|
|
429
451
|
return resolvedRoute as any
|
|
@@ -478,7 +500,7 @@ export function useNavigate<
|
|
|
478
500
|
return React.useCallback(
|
|
479
501
|
<
|
|
480
502
|
TFrom extends keyof RegisteredRoutesInfo['routesById'] = TDefaultFrom,
|
|
481
|
-
TTo extends string = '
|
|
503
|
+
TTo extends string = '',
|
|
482
504
|
>(
|
|
483
505
|
opts?: MakeLinkOptions<TFrom, TTo>,
|
|
484
506
|
) => {
|
|
@@ -494,7 +516,7 @@ export function useMatchRoute() {
|
|
|
494
516
|
return React.useCallback(
|
|
495
517
|
<
|
|
496
518
|
TFrom extends ValidFromPath<RegisteredRoutesInfo> = '/',
|
|
497
|
-
TTo extends string = '
|
|
519
|
+
TTo extends string = '',
|
|
498
520
|
>(
|
|
499
521
|
opts: MakeUseMatchRouteOptions<TFrom, TTo>,
|
|
500
522
|
) => {
|
|
@@ -511,7 +533,7 @@ export function useMatchRoute() {
|
|
|
511
533
|
|
|
512
534
|
export function MatchRoute<
|
|
513
535
|
TFrom extends ValidFromPath<RegisteredRoutesInfo> = '/',
|
|
514
|
-
TTo extends string = '
|
|
536
|
+
TTo extends string = '',
|
|
515
537
|
>(props: MakeMatchRouteOptions<TFrom, TTo>): any {
|
|
516
538
|
const matchRoute = useMatchRoute()
|
|
517
539
|
const params = matchRoute(props)
|