@tanstack/react-router 0.0.1-beta.221 → 0.0.1-beta.223
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/Matches.js.map +1 -1
- package/build/cjs/RouterProvider.js +12 -7
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/useSearch.js.map +1 -1
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +12 -7
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +279 -279
- package/build/types/Matches.d.ts +25 -2
- package/build/types/RouterProvider.d.ts +2 -24
- package/build/types/fileRoute.d.ts +3 -3
- package/build/types/route.d.ts +2 -1
- package/build/types/router.d.ts +1 -1
- package/build/umd/index.development.js +12 -7
- 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/Matches.tsx +38 -2
- package/src/RouterProvider.tsx +16 -41
- package/src/route.ts +2 -1
- package/src/router.ts +1 -1
- package/src/useSearch.tsx +1 -1
- package/src/utils.ts +1 -1
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-beta.
|
|
4
|
+
"version": "0.0.1-beta.223",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@babel/runtime": "^7.16.7",
|
|
43
43
|
"tiny-invariant": "^1.3.1",
|
|
44
44
|
"tiny-warning": "^1.0.3",
|
|
45
|
-
"@tanstack/history": "0.0.1-beta.
|
|
45
|
+
"@tanstack/history": "0.0.1-beta.223"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "rollup --config rollup.config.js"
|
package/src/Matches.tsx
CHANGED
|
@@ -2,14 +2,50 @@ import * as React from 'react'
|
|
|
2
2
|
import invariant from 'tiny-invariant'
|
|
3
3
|
import warning from 'tiny-warning'
|
|
4
4
|
import { CatchBoundary, ErrorComponent } from './CatchBoundary'
|
|
5
|
-
import { RouteMatch } from './RouterProvider'
|
|
6
5
|
import { useRouter, useRouterState } from './RouterProvider'
|
|
7
6
|
import { ResolveRelativePath, ToOptions } from './link'
|
|
8
7
|
import { AnyRoute, ReactNode, rootRouteId } from './route'
|
|
9
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
FullSearchSchema,
|
|
10
|
+
ParseRoute,
|
|
11
|
+
RouteById,
|
|
12
|
+
RouteByPath,
|
|
13
|
+
RouteIds,
|
|
14
|
+
RoutePaths,
|
|
15
|
+
} from './routeInfo'
|
|
10
16
|
import { RegisteredRouter } from './router'
|
|
11
17
|
import { NoInfer, StrictOrFrom } from './utils'
|
|
12
18
|
|
|
19
|
+
export interface RouteMatch<
|
|
20
|
+
TRouteTree extends AnyRoute = AnyRoute,
|
|
21
|
+
TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
|
|
22
|
+
> {
|
|
23
|
+
id: string
|
|
24
|
+
routeId: TRouteId
|
|
25
|
+
pathname: string
|
|
26
|
+
params: RouteById<TRouteTree, TRouteId>['types']['allParams']
|
|
27
|
+
status: 'pending' | 'success' | 'error'
|
|
28
|
+
isFetching: boolean
|
|
29
|
+
invalid: boolean
|
|
30
|
+
error: unknown
|
|
31
|
+
paramsError: unknown
|
|
32
|
+
searchError: unknown
|
|
33
|
+
updatedAt: number
|
|
34
|
+
loadPromise?: Promise<void>
|
|
35
|
+
loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData']
|
|
36
|
+
__resolveLoadPromise?: () => void
|
|
37
|
+
context: RouteById<TRouteTree, TRouteId>['types']['allContext']
|
|
38
|
+
routeSearch: RouteById<TRouteTree, TRouteId>['types']['searchSchema']
|
|
39
|
+
search: FullSearchSchema<TRouteTree> &
|
|
40
|
+
RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema']
|
|
41
|
+
fetchedAt: number
|
|
42
|
+
shouldReloadDeps: any
|
|
43
|
+
abortController: AbortController
|
|
44
|
+
cause: 'enter' | 'stay'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type AnyRouteMatch = RouteMatch<any>
|
|
48
|
+
|
|
13
49
|
export function Matches() {
|
|
14
50
|
const { routesById, state } = useRouter()
|
|
15
51
|
const { matches } = state
|
package/src/RouterProvider.tsx
CHANGED
|
@@ -36,9 +36,7 @@ import {
|
|
|
36
36
|
} from './route'
|
|
37
37
|
import {
|
|
38
38
|
FullSearchSchema,
|
|
39
|
-
ParseRoute,
|
|
40
39
|
RouteById,
|
|
41
|
-
RouteIds,
|
|
42
40
|
RoutePaths,
|
|
43
41
|
RoutesById,
|
|
44
42
|
RoutesByPath,
|
|
@@ -64,6 +62,7 @@ import {
|
|
|
64
62
|
escapeJSON,
|
|
65
63
|
} from './utils'
|
|
66
64
|
import { MatchRouteOptions } from './Matches'
|
|
65
|
+
import { AnyRouteMatch, RouteMatch } from './Matches'
|
|
67
66
|
|
|
68
67
|
export interface CommitLocationOptions {
|
|
69
68
|
replace?: boolean
|
|
@@ -475,8 +474,12 @@ export function RouterProvider<
|
|
|
475
474
|
// around between navigation actions that only change leaf routes.
|
|
476
475
|
const existingMatch = getRouteMatch(state, matchId)
|
|
477
476
|
|
|
477
|
+
const cause = state.matches.find((d) => d.id === matchId)
|
|
478
|
+
? 'stay'
|
|
479
|
+
: 'enter'
|
|
480
|
+
|
|
478
481
|
if (existingMatch) {
|
|
479
|
-
return { ...existingMatch }
|
|
482
|
+
return { ...existingMatch, cause }
|
|
480
483
|
}
|
|
481
484
|
|
|
482
485
|
// Create a fresh route match
|
|
@@ -504,6 +507,7 @@ export function RouterProvider<
|
|
|
504
507
|
abortController: new AbortController(),
|
|
505
508
|
shouldReloadDeps: undefined,
|
|
506
509
|
fetchedAt: 0,
|
|
510
|
+
cause,
|
|
507
511
|
}
|
|
508
512
|
|
|
509
513
|
return routeMatch
|
|
@@ -922,6 +926,7 @@ export function RouterProvider<
|
|
|
922
926
|
navigate: (opts) =>
|
|
923
927
|
navigate({ ...opts, from: match.pathname } as any),
|
|
924
928
|
buildLocation,
|
|
929
|
+
cause: match.cause,
|
|
925
930
|
})) ?? ({} as any)
|
|
926
931
|
|
|
927
932
|
const context = {
|
|
@@ -977,10 +982,6 @@ export function RouterProvider<
|
|
|
977
982
|
if (match.isFetching) {
|
|
978
983
|
loadPromise = getRouteMatch(state, match.id)?.loadPromise
|
|
979
984
|
} else {
|
|
980
|
-
const cause = state.matches.find((d) => d.id === match.id)
|
|
981
|
-
? 'stay'
|
|
982
|
-
: 'enter'
|
|
983
|
-
|
|
984
985
|
const loaderContext: LoaderFnContext = {
|
|
985
986
|
params: match.params,
|
|
986
987
|
search: match.search,
|
|
@@ -991,18 +992,20 @@ export function RouterProvider<
|
|
|
991
992
|
location: state.location,
|
|
992
993
|
navigate: (opts) =>
|
|
993
994
|
navigate({ ...opts, from: match.pathname } as any),
|
|
994
|
-
cause,
|
|
995
|
+
cause: match.cause,
|
|
995
996
|
}
|
|
996
997
|
|
|
997
998
|
// Default to reloading the route all the time
|
|
998
999
|
let shouldReload = true
|
|
999
1000
|
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
: !!(route.options.shouldReload ?? true)
|
|
1001
|
+
let shouldReloadDeps =
|
|
1002
|
+
typeof route.options.shouldReload === 'function'
|
|
1003
|
+
? route.options.shouldReload?.(loaderContext)
|
|
1004
|
+
: !!(route.options.shouldReload ?? true)
|
|
1005
1005
|
|
|
1006
|
+
if (match.cause === 'enter') {
|
|
1007
|
+
match.shouldReloadDeps = shouldReloadDeps
|
|
1008
|
+
} else if (match.cause === 'stay') {
|
|
1006
1009
|
if (typeof shouldReloadDeps === 'object') {
|
|
1007
1010
|
// compare the deps to see if they've changed
|
|
1008
1011
|
shouldReload = !deepEqual(
|
|
@@ -1545,31 +1548,3 @@ export function useRouter<
|
|
|
1545
1548
|
warning(value, 'useRouter must be used inside a <RouterProvider> component!')
|
|
1546
1549
|
return value as any
|
|
1547
1550
|
}
|
|
1548
|
-
export interface RouteMatch<
|
|
1549
|
-
TRouteTree extends AnyRoute = AnyRoute,
|
|
1550
|
-
TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
|
|
1551
|
-
> {
|
|
1552
|
-
id: string
|
|
1553
|
-
routeId: TRouteId
|
|
1554
|
-
pathname: string
|
|
1555
|
-
params: RouteById<TRouteTree, TRouteId>['types']['allParams']
|
|
1556
|
-
status: 'pending' | 'success' | 'error'
|
|
1557
|
-
isFetching: boolean
|
|
1558
|
-
invalid: boolean
|
|
1559
|
-
error: unknown
|
|
1560
|
-
paramsError: unknown
|
|
1561
|
-
searchError: unknown
|
|
1562
|
-
updatedAt: number
|
|
1563
|
-
loadPromise?: Promise<void>
|
|
1564
|
-
loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData']
|
|
1565
|
-
__resolveLoadPromise?: () => void
|
|
1566
|
-
context: RouteById<TRouteTree, TRouteId>['types']['allContext']
|
|
1567
|
-
routeSearch: RouteById<TRouteTree, TRouteId>['types']['searchSchema']
|
|
1568
|
-
search: FullSearchSchema<TRouteTree> &
|
|
1569
|
-
RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema']
|
|
1570
|
-
fetchedAt: number
|
|
1571
|
-
shouldReloadDeps: any
|
|
1572
|
-
abortController: AbortController
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1575
|
-
export type AnyRouteMatch = RouteMatch<any>
|
package/src/route.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { HistoryLocation } from '@tanstack/history'
|
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
import invariant from 'tiny-invariant'
|
|
4
4
|
import { useLoaderData, useMatch } from './Matches'
|
|
5
|
-
import { AnyRouteMatch } from './
|
|
5
|
+
import { AnyRouteMatch } from './Matches'
|
|
6
6
|
import { NavigateOptions, ParsePathParams, ToSubOptions } from './link'
|
|
7
7
|
import { ParsedLocation } from './location'
|
|
8
8
|
import { joinPaths, trimPath } from './path'
|
|
@@ -178,6 +178,7 @@ type BeforeLoadFn<
|
|
|
178
178
|
location: ParsedLocation
|
|
179
179
|
navigate: NavigateFn<AnyRoute>
|
|
180
180
|
buildLocation: BuildLocationFn<AnyRoute>
|
|
181
|
+
cause: 'enter' | 'stay'
|
|
181
182
|
}) => Promise<TRouteContext> | TRouteContext | void
|
|
182
183
|
|
|
183
184
|
export type UpdatableRouteOptions<
|
package/src/router.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
PendingRouteComponent,
|
|
18
18
|
RouteComponent,
|
|
19
19
|
} from './route'
|
|
20
|
-
import { RouteMatch } from './
|
|
20
|
+
import { RouteMatch } from './Matches'
|
|
21
21
|
import { ParsedLocation } from './location'
|
|
22
22
|
import { LocationState } from './location'
|
|
23
23
|
import { SearchSerializer, SearchParser } from './searchParams'
|
package/src/useSearch.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnyRoute } from './route'
|
|
2
2
|
import { RouteIds, RouteById } from './routeInfo'
|
|
3
3
|
import { RegisteredRouter } from './router'
|
|
4
|
-
import { RouteMatch } from './
|
|
4
|
+
import { RouteMatch } from './Matches'
|
|
5
5
|
import { useMatch } from './Matches'
|
|
6
6
|
import { StrictOrFrom } from './utils'
|
|
7
7
|
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { useMatch } from './Matches'
|
|
3
|
-
import { RouteMatch } from './
|
|
3
|
+
import { RouteMatch } from './Matches'
|
|
4
4
|
import { AnyRoute } from './route'
|
|
5
5
|
import { ParseRoute, RouteIds, RoutesById, RouteById } from './routeInfo'
|
|
6
6
|
import { RegisteredRouter } from './router'
|