@tanstack/react-router 0.0.1-beta.1 → 0.0.1-beta.11
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/react-router/src/index.js +39 -69
- package/build/cjs/react-router/src/index.js.map +1 -1
- package/build/cjs/router-core/build/esm/index.js +143 -119
- package/build/cjs/router-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +181 -187
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +29 -29
- package/build/types/index.d.ts +6 -2
- package/build/umd/index.development.js +181 -187
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +4 -3
- package/src/index.tsx +58 -69
- package/src/qss.ts +0 -53
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.0.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.11",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
|
-
"homepage": "https://
|
|
7
|
+
"homepage": "https://tanstack.com/router/",
|
|
8
8
|
"description": "",
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -34,13 +34,14 @@
|
|
|
34
34
|
"build/**",
|
|
35
35
|
"src"
|
|
36
36
|
],
|
|
37
|
+
"sideEffects": false,
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"react": ">=16",
|
|
39
40
|
"react-dom": ">=16"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
43
|
"@babel/runtime": "^7.16.7",
|
|
43
|
-
"@tanstack/router-core": "0.0.1-beta.
|
|
44
|
+
"@tanstack/router-core": "0.0.1-beta.11",
|
|
44
45
|
"use-sync-external-store": "^1.2.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
package/src/index.tsx
CHANGED
|
@@ -50,9 +50,17 @@ declare module '@tanstack/router-core' {
|
|
|
50
50
|
useRoute: <TId extends keyof TAllRouteInfo['routeInfoById']>(
|
|
51
51
|
routeId: TId,
|
|
52
52
|
) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>
|
|
53
|
-
useMatch: <
|
|
53
|
+
useMatch: <
|
|
54
|
+
TId extends keyof TAllRouteInfo['routeInfoById'],
|
|
55
|
+
TStrict extends true | false = true,
|
|
56
|
+
>(
|
|
54
57
|
routeId: TId,
|
|
55
|
-
|
|
58
|
+
opts?: { strict?: TStrict },
|
|
59
|
+
) => TStrict extends true
|
|
60
|
+
? RouteMatch<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>
|
|
61
|
+
:
|
|
62
|
+
| RouteMatch<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>
|
|
63
|
+
| undefined
|
|
56
64
|
linkProps: <TTo extends string = '.'>(
|
|
57
65
|
props: LinkPropsOptions<TAllRouteInfo, '/', TTo> &
|
|
58
66
|
React.AnchorHTMLAttributes<HTMLAnchorElement>,
|
|
@@ -99,6 +107,7 @@ declare module '@tanstack/router-core' {
|
|
|
99
107
|
TResolved,
|
|
100
108
|
ToIdOption<TAllRouteInfo, TRouteInfo['id'], TTo>
|
|
101
109
|
>,
|
|
110
|
+
opts?: { strict?: boolean },
|
|
102
111
|
) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TResolved]>
|
|
103
112
|
linkProps: <TTo extends string = '.'>(
|
|
104
113
|
props: LinkPropsOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo> &
|
|
@@ -179,6 +188,7 @@ const useRouterSubscription = (router: Router<any, any>) => {
|
|
|
179
188
|
useSyncExternalStore(
|
|
180
189
|
(cb) => router.subscribe(() => cb()),
|
|
181
190
|
() => router.state,
|
|
191
|
+
() => router.state,
|
|
182
192
|
)
|
|
183
193
|
}
|
|
184
194
|
|
|
@@ -348,7 +358,7 @@ export function createReactRouter<
|
|
|
348
358
|
useRouterSubscription(router)
|
|
349
359
|
return router.state
|
|
350
360
|
},
|
|
351
|
-
useMatch: (routeId) => {
|
|
361
|
+
useMatch: (routeId, opts) => {
|
|
352
362
|
useRouterSubscription(router)
|
|
353
363
|
|
|
354
364
|
invariant(
|
|
@@ -356,32 +366,30 @@ export function createReactRouter<
|
|
|
356
366
|
`"${rootRouteId}" cannot be used with useMatch! Did you mean to useRoute("${rootRouteId}")?`,
|
|
357
367
|
)
|
|
358
368
|
|
|
359
|
-
const runtimeMatch =
|
|
369
|
+
const runtimeMatch = useMatches()?.[0]!
|
|
360
370
|
const match = router.state.matches.find((d) => d.routeId === routeId)
|
|
361
371
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
routeId as string
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
if (!match) {
|
|
381
|
-
invariant('Match not found!')
|
|
372
|
+
if (opts?.strict ?? true) {
|
|
373
|
+
invariant(
|
|
374
|
+
match,
|
|
375
|
+
`Could not find an active match for "${routeId as string}"!`,
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
invariant(
|
|
379
|
+
runtimeMatch.routeId == match?.routeId,
|
|
380
|
+
`useMatch('${
|
|
381
|
+
match?.routeId as string
|
|
382
|
+
}') is being called in a component that is meant to render the '${
|
|
383
|
+
runtimeMatch.routeId
|
|
384
|
+
}' route. Did you mean to 'useMatch(${
|
|
385
|
+
match?.routeId as string
|
|
386
|
+
}, { strict: false })' or 'useRoute(${
|
|
387
|
+
match?.routeId as string
|
|
388
|
+
})' instead?`,
|
|
389
|
+
)
|
|
382
390
|
}
|
|
383
391
|
|
|
384
|
-
return match
|
|
392
|
+
return match as any
|
|
385
393
|
},
|
|
386
394
|
}
|
|
387
395
|
|
|
@@ -429,9 +437,10 @@ export function RouterProvider<
|
|
|
429
437
|
router.update(rest)
|
|
430
438
|
|
|
431
439
|
useRouterSubscription(router)
|
|
432
|
-
|
|
433
440
|
useLayoutEffect(() => {
|
|
434
|
-
|
|
441
|
+
const unsub = router.mount()
|
|
442
|
+
router.load()
|
|
443
|
+
return unsub
|
|
435
444
|
}, [router])
|
|
436
445
|
|
|
437
446
|
return (
|
|
@@ -456,57 +465,41 @@ function useMatches(): RouteMatch[] {
|
|
|
456
465
|
return React.useContext(matchesContext)
|
|
457
466
|
}
|
|
458
467
|
|
|
459
|
-
// function useParentMatches(): RouteMatch[] {
|
|
460
|
-
// const router = useRouter()
|
|
461
|
-
// const match = useMatch()
|
|
462
|
-
// const matches = router.state.matches
|
|
463
|
-
// return matches.slice(
|
|
464
|
-
// 0,
|
|
465
|
-
// matches.findIndex((d) => d.matchId === match.matchId) - 1,
|
|
466
|
-
// )
|
|
467
|
-
// }
|
|
468
|
-
|
|
469
|
-
function useMatch<T>(): RouteMatch {
|
|
470
|
-
return useMatches()?.[0] as RouteMatch
|
|
471
|
-
}
|
|
472
|
-
|
|
473
468
|
export function Outlet() {
|
|
474
469
|
const router = useRouter()
|
|
475
|
-
const
|
|
470
|
+
const matches = useMatches().slice(1)
|
|
471
|
+
const match = matches[0]
|
|
476
472
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
473
|
+
if (!match) {
|
|
474
|
+
return null
|
|
475
|
+
}
|
|
480
476
|
|
|
481
477
|
const element = ((): React.ReactNode => {
|
|
482
|
-
if (!
|
|
478
|
+
if (!match) {
|
|
483
479
|
return null
|
|
484
480
|
}
|
|
485
481
|
|
|
486
482
|
const errorElement =
|
|
487
|
-
|
|
483
|
+
match.__.errorElement ?? router.options.defaultErrorElement
|
|
488
484
|
|
|
489
|
-
if (
|
|
485
|
+
if (match.status === 'error') {
|
|
490
486
|
if (errorElement) {
|
|
491
487
|
return errorElement as any
|
|
492
488
|
}
|
|
493
489
|
|
|
494
|
-
if (
|
|
495
|
-
|
|
496
|
-
router.options.useErrorBoundary
|
|
497
|
-
) {
|
|
498
|
-
throw childMatch.error
|
|
490
|
+
if (match.options.useErrorBoundary || router.options.useErrorBoundary) {
|
|
491
|
+
throw match.error
|
|
499
492
|
}
|
|
500
493
|
|
|
501
|
-
return <DefaultErrorBoundary error={
|
|
494
|
+
return <DefaultErrorBoundary error={match.error} />
|
|
502
495
|
}
|
|
503
496
|
|
|
504
|
-
if (
|
|
505
|
-
if (
|
|
497
|
+
if (match.status === 'loading' || match.status === 'idle') {
|
|
498
|
+
if (match.isPending) {
|
|
506
499
|
const pendingElement =
|
|
507
|
-
|
|
500
|
+
match.__.pendingElement ?? router.options.defaultPendingElement
|
|
508
501
|
|
|
509
|
-
if (
|
|
502
|
+
if (match.options.pendingMs || pendingElement) {
|
|
510
503
|
return (pendingElement as any) ?? null
|
|
511
504
|
}
|
|
512
505
|
}
|
|
@@ -514,14 +507,16 @@ export function Outlet() {
|
|
|
514
507
|
return null
|
|
515
508
|
}
|
|
516
509
|
|
|
517
|
-
return (
|
|
510
|
+
return (
|
|
511
|
+
(match.__.element as any) ?? router.options.defaultElement ?? <Outlet />
|
|
512
|
+
)
|
|
518
513
|
})() as JSX.Element
|
|
519
514
|
|
|
520
515
|
const catchElement =
|
|
521
|
-
|
|
516
|
+
match?.options.catchElement ?? router.options.defaultCatchElement
|
|
522
517
|
|
|
523
518
|
return (
|
|
524
|
-
<MatchesProvider value={matches}
|
|
519
|
+
<MatchesProvider value={matches}>
|
|
525
520
|
<CatchBoundary catchElement={catchElement}>{element}</CatchBoundary>
|
|
526
521
|
</MatchesProvider>
|
|
527
522
|
)
|
|
@@ -542,12 +537,6 @@ class CatchBoundary extends React.Component<{
|
|
|
542
537
|
info,
|
|
543
538
|
})
|
|
544
539
|
}
|
|
545
|
-
reset = () => {
|
|
546
|
-
this.setState({
|
|
547
|
-
error: false,
|
|
548
|
-
info: false,
|
|
549
|
-
})
|
|
550
|
-
}
|
|
551
540
|
render() {
|
|
552
541
|
const catchElement = this.props.catchElement ?? DefaultErrorBoundary
|
|
553
542
|
|
|
@@ -583,7 +572,7 @@ export function DefaultErrorBoundary({ error }: { error: any }) {
|
|
|
583
572
|
) : null}
|
|
584
573
|
</pre>
|
|
585
574
|
</div>
|
|
586
|
-
<div style={{ height: '1rem' }} />
|
|
575
|
+
{/* <div style={{ height: '1rem' }} />
|
|
587
576
|
<div
|
|
588
577
|
style={{
|
|
589
578
|
fontSize: '.8em',
|
|
@@ -595,7 +584,7 @@ export function DefaultErrorBoundary({ error }: { error: any }) {
|
|
|
595
584
|
If you are the owner of this website, it's highly recommended that you
|
|
596
585
|
configure your own custom Catch/Error boundaries for the router. You can
|
|
597
586
|
optionally configure a boundary for each route.
|
|
598
|
-
</div>
|
|
587
|
+
</div> */}
|
|
599
588
|
</div>
|
|
600
589
|
)
|
|
601
590
|
}
|
package/src/qss.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
|
-
// We're inlining qss here for compression's sake, but we've included it as a hard dependency for the MIT license it requires.
|
|
4
|
-
|
|
5
|
-
export function encode(obj, pfx?: string) {
|
|
6
|
-
var k,
|
|
7
|
-
i,
|
|
8
|
-
tmp,
|
|
9
|
-
str = ''
|
|
10
|
-
|
|
11
|
-
for (k in obj) {
|
|
12
|
-
if ((tmp = obj[k]) !== void 0) {
|
|
13
|
-
if (Array.isArray(tmp)) {
|
|
14
|
-
for (i = 0; i < tmp.length; i++) {
|
|
15
|
-
str && (str += '&')
|
|
16
|
-
str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i])
|
|
17
|
-
}
|
|
18
|
-
} else {
|
|
19
|
-
str && (str += '&')
|
|
20
|
-
str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return (pfx || '') + str
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function toValue(mix) {
|
|
29
|
-
if (!mix) return ''
|
|
30
|
-
var str = decodeURIComponent(mix)
|
|
31
|
-
if (str === 'false') return false
|
|
32
|
-
if (str === 'true') return true
|
|
33
|
-
return +str * 0 === 0 ? +str : str
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function decode(str) {
|
|
37
|
-
var tmp,
|
|
38
|
-
k,
|
|
39
|
-
out = {},
|
|
40
|
-
arr = str.split('&')
|
|
41
|
-
|
|
42
|
-
while ((tmp = arr.shift())) {
|
|
43
|
-
tmp = tmp.split('=')
|
|
44
|
-
k = tmp.shift()
|
|
45
|
-
if (out[k] !== void 0) {
|
|
46
|
-
out[k] = [].concat(out[k], toValue(tmp.shift()))
|
|
47
|
-
} else {
|
|
48
|
-
out[k] = toValue(tmp.shift())
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return out
|
|
53
|
-
}
|