@tanstack/react-router 0.0.1-alpha.6 → 0.0.1-alpha.7
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 +35 -20
- package/build/cjs/react-router/src/index.js.map +1 -1
- package/build/cjs/router-core/build/esm/index.js +1312 -1242
- package/build/cjs/router-core/build/esm/index.js.map +1 -1
- package/build/esm/index.js +1343 -1276
- 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 +4 -3
- package/build/umd/index.development.js +1353 -1277
- 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/index.tsx +24 -18
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.0.1-alpha.
|
|
4
|
+
"version": "0.0.1-alpha.7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://react-router.tanstack.com/",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@babel/runtime": "^7.16.7",
|
|
43
|
-
"@tanstack/router-core": "0.0.1-alpha.
|
|
43
|
+
"@tanstack/router-core": "0.0.1-alpha.7",
|
|
44
44
|
"use-sync-external-store": "^1.2.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
package/src/index.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
RootRouteId,
|
|
8
8
|
rootRouteId,
|
|
9
9
|
Router,
|
|
10
|
+
RouterState,
|
|
10
11
|
} from '@tanstack/router-core'
|
|
11
12
|
import {
|
|
12
13
|
warning,
|
|
@@ -49,6 +50,7 @@ declare module '@tanstack/router-core' {
|
|
|
49
50
|
Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][RootRouteId]>,
|
|
50
51
|
'linkProps' | 'Link' | 'MatchRoute'
|
|
51
52
|
> {
|
|
53
|
+
useState: () => RouterState
|
|
52
54
|
useRoute: <TId extends keyof TAllRouteInfo['routeInfoById']>(
|
|
53
55
|
routeId: TId,
|
|
54
56
|
) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>
|
|
@@ -237,11 +239,11 @@ export function createReactRouter<
|
|
|
237
239
|
|
|
238
240
|
// Get the active props
|
|
239
241
|
const resolvedActiveProps: React.HTMLAttributes<HTMLAnchorElement> =
|
|
240
|
-
isActive ? functionalUpdate(activeProps) ?? {} : {}
|
|
242
|
+
isActive ? functionalUpdate(activeProps, {}) ?? {} : {}
|
|
241
243
|
|
|
242
244
|
// Get the inactive props
|
|
243
245
|
const resolvedInactiveProps: React.HTMLAttributes<HTMLAnchorElement> =
|
|
244
|
-
isActive ? {} : functionalUpdate(inactiveProps) ?? {}
|
|
246
|
+
isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {}
|
|
245
247
|
|
|
246
248
|
return {
|
|
247
249
|
...resolvedActiveProps,
|
|
@@ -303,8 +305,6 @@ export function createReactRouter<
|
|
|
303
305
|
caseSensitive,
|
|
304
306
|
})
|
|
305
307
|
|
|
306
|
-
// useRouterSubscription(router)
|
|
307
|
-
|
|
308
308
|
if (!params) {
|
|
309
309
|
return null
|
|
310
310
|
}
|
|
@@ -319,7 +319,14 @@ export function createReactRouter<
|
|
|
319
319
|
const coreRouter = createRouter<TRouteConfig>({
|
|
320
320
|
...opts,
|
|
321
321
|
createRouter: (router) => {
|
|
322
|
-
const routerExt: Pick<
|
|
322
|
+
const routerExt: Pick<
|
|
323
|
+
Router<any, any>,
|
|
324
|
+
'useRoute' | 'useMatch' | 'useState'
|
|
325
|
+
> = {
|
|
326
|
+
useState: () => {
|
|
327
|
+
useRouterSubscription(router)
|
|
328
|
+
return router.state
|
|
329
|
+
},
|
|
323
330
|
useRoute: (routeId) => {
|
|
324
331
|
const route = router.getRoute(routeId)
|
|
325
332
|
useRouterSubscription(router)
|
|
@@ -332,6 +339,8 @@ export function createReactRouter<
|
|
|
332
339
|
return route
|
|
333
340
|
},
|
|
334
341
|
useMatch: (routeId) => {
|
|
342
|
+
useRouterSubscription(router)
|
|
343
|
+
|
|
335
344
|
invariant(
|
|
336
345
|
routeId !== rootRouteId,
|
|
337
346
|
`"${rootRouteId}" cannot be used with useMatch! Did you mean to useRoute("${rootRouteId}")?`,
|
|
@@ -358,8 +367,6 @@ export function createReactRouter<
|
|
|
358
367
|
})' instead?`,
|
|
359
368
|
)
|
|
360
369
|
|
|
361
|
-
useRouterSubscription(router)
|
|
362
|
-
|
|
363
370
|
if (!match) {
|
|
364
371
|
invariant('Match not found!')
|
|
365
372
|
}
|
|
@@ -397,14 +404,11 @@ export function RouterProvider<
|
|
|
397
404
|
>({ children, router, ...rest }: RouterProps<TRouteConfig, TAllRouteInfo>) {
|
|
398
405
|
router.update(rest)
|
|
399
406
|
|
|
400
|
-
|
|
401
|
-
(cb) => router.subscribe(() => cb()),
|
|
402
|
-
() => router.state,
|
|
403
|
-
)
|
|
407
|
+
useRouterSubscription(router)
|
|
404
408
|
|
|
405
409
|
useLayoutEffect(() => {
|
|
406
|
-
router.mount()
|
|
407
|
-
}, [])
|
|
410
|
+
return router.mount()
|
|
411
|
+
}, [router])
|
|
408
412
|
|
|
409
413
|
return (
|
|
410
414
|
<routerContext.Provider value={{ router }}>
|
|
@@ -450,7 +454,7 @@ export function Outlet() {
|
|
|
450
454
|
|
|
451
455
|
if (!childMatch) return null
|
|
452
456
|
|
|
453
|
-
const element = ((
|
|
457
|
+
const element = ((): React.ReactNode => {
|
|
454
458
|
if (!childMatch) {
|
|
455
459
|
return null
|
|
456
460
|
}
|
|
@@ -470,7 +474,7 @@ export function Outlet() {
|
|
|
470
474
|
throw childMatch.error
|
|
471
475
|
}
|
|
472
476
|
|
|
473
|
-
return <
|
|
477
|
+
return <DefaultErrorBoundary error={childMatch.error} />
|
|
474
478
|
}
|
|
475
479
|
|
|
476
480
|
if (childMatch.status === 'loading' || childMatch.status === 'idle') {
|
|
@@ -487,7 +491,7 @@ export function Outlet() {
|
|
|
487
491
|
}
|
|
488
492
|
|
|
489
493
|
return (childMatch.__.element as any) ?? router.options.defaultElement
|
|
490
|
-
})() as JSX.Element
|
|
494
|
+
})() as JSX.Element
|
|
491
495
|
|
|
492
496
|
const catchElement =
|
|
493
497
|
childMatch?.options.catchElement ?? router.options.defaultCatchElement
|
|
@@ -521,7 +525,7 @@ class CatchBoundary extends React.Component<{
|
|
|
521
525
|
})
|
|
522
526
|
}
|
|
523
527
|
render() {
|
|
524
|
-
const catchElement = this.props.catchElement ??
|
|
528
|
+
const catchElement = this.props.catchElement ?? DefaultErrorBoundary
|
|
525
529
|
|
|
526
530
|
if (this.state.error) {
|
|
527
531
|
return typeof catchElement === 'function'
|
|
@@ -533,7 +537,7 @@ class CatchBoundary extends React.Component<{
|
|
|
533
537
|
}
|
|
534
538
|
}
|
|
535
539
|
|
|
536
|
-
export function
|
|
540
|
+
export function DefaultErrorBoundary({ error }: { error: any }) {
|
|
537
541
|
return (
|
|
538
542
|
<div style={{ padding: '.5rem', maxWidth: '100%' }}>
|
|
539
543
|
<strong style={{ fontSize: '1.2rem' }}>Something went wrong!</strong>
|
|
@@ -571,3 +575,5 @@ export function DefaultCatchBoundary({ error }: { error: any }) {
|
|
|
571
575
|
</div>
|
|
572
576
|
)
|
|
573
577
|
}
|
|
578
|
+
|
|
579
|
+
// TODO: Add prompt
|