@tanstack/router-core 0.0.1-beta.50 → 0.0.1-beta.51
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/actions.js +1 -1
- package/build/cjs/actions.js.map +1 -1
- package/build/cjs/routeMatch.js +1 -1
- package/build/cjs/routeMatch.js.map +1 -1
- package/build/cjs/router.js +12 -9
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +14 -11
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +152 -152
- package/build/types/index.d.ts +3 -3
- package/build/umd/index.development.js +14 -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 +1 -1
- package/src/actions.ts +1 -1
- package/src/routeMatch.ts +2 -3
- package/src/router.ts +26 -13
package/package.json
CHANGED
package/src/actions.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// RouterAction is a constrained identify function that takes options: key, action, onSuccess, onError, onSettled, etc
|
|
2
2
|
|
|
3
3
|
import invariant from 'tiny-invariant'
|
|
4
4
|
import { batch, createStore, Store } from './store'
|
package/src/routeMatch.ts
CHANGED
|
@@ -67,7 +67,7 @@ export class RouteMatch<
|
|
|
67
67
|
router: AnyRouter,
|
|
68
68
|
route: Route<TAllRouteInfo, TRouteInfo>,
|
|
69
69
|
opts: {
|
|
70
|
-
|
|
70
|
+
id: string
|
|
71
71
|
params: TRouteInfo['allParams']
|
|
72
72
|
pathname: string
|
|
73
73
|
},
|
|
@@ -75,7 +75,7 @@ export class RouteMatch<
|
|
|
75
75
|
Object.assign(this, {
|
|
76
76
|
route,
|
|
77
77
|
router,
|
|
78
|
-
|
|
78
|
+
id: opts.id,
|
|
79
79
|
pathname: opts.pathname,
|
|
80
80
|
params: opts.params,
|
|
81
81
|
store: createStore<RouteMatchStore<TAllRouteInfo, TRouteInfo>>({
|
|
@@ -197,7 +197,6 @@ export class RouteMatch<
|
|
|
197
197
|
if (this.route.options.loader) {
|
|
198
198
|
const data = await this.router.loadMatchData(this)
|
|
199
199
|
if ((latestPromise = checkLatest())) return latestPromise
|
|
200
|
-
|
|
201
200
|
this.#setLoaderData(data)
|
|
202
201
|
}
|
|
203
202
|
|
package/src/router.ts
CHANGED
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
createMemoryHistory,
|
|
53
53
|
RouterHistory,
|
|
54
54
|
} from './history'
|
|
55
|
+
import { createMemo } from '@solidjs/reactivity'
|
|
55
56
|
|
|
56
57
|
export interface RegisterRouter {
|
|
57
58
|
// router: Router
|
|
@@ -120,7 +121,7 @@ export interface RouterOptions<
|
|
|
120
121
|
routeConfig?: TRouteConfig
|
|
121
122
|
basepath?: string
|
|
122
123
|
useServerData?: boolean
|
|
123
|
-
|
|
124
|
+
Router?: (router: AnyRouter) => void
|
|
124
125
|
createRoute?: (opts: { route: AnyRoute; router: AnyRouter }) => void
|
|
125
126
|
context?: TRouterContext
|
|
126
127
|
loadComponent?: (
|
|
@@ -243,7 +244,7 @@ export interface DehydratedRouter<TRouterContext = unknown> {
|
|
|
243
244
|
export type MatchCache = Record<string, MatchCacheEntry>
|
|
244
245
|
|
|
245
246
|
interface DehydratedRouteMatch {
|
|
246
|
-
|
|
247
|
+
id: string
|
|
247
248
|
state: Pick<
|
|
248
249
|
RouteMatchStore<any, any>,
|
|
249
250
|
'status' | 'routeLoaderData' | 'invalid' | 'invalidAt'
|
|
@@ -293,7 +294,7 @@ export class Router<
|
|
|
293
294
|
RouterOptions<TRouteConfig, TRouterContext>,
|
|
294
295
|
'stringifySearch' | 'parseSearch' | 'context'
|
|
295
296
|
>
|
|
296
|
-
history
|
|
297
|
+
history!: RouterHistory
|
|
297
298
|
basepath: string
|
|
298
299
|
// __location: Location<TAllRouteInfo['fullSearchSchema']>
|
|
299
300
|
routeTree!: Route<TAllRouteInfo, RouteInfo>
|
|
@@ -319,14 +320,13 @@ export class Router<
|
|
|
319
320
|
fetchServerDataFn: options?.fetchServerDataFn ?? defaultFetchServerDataFn,
|
|
320
321
|
}
|
|
321
322
|
|
|
322
|
-
this.history = this.options?.history ?? createBrowserHistory()
|
|
323
323
|
this.store = createStore(getInitialRouterState())
|
|
324
324
|
this.basepath = ''
|
|
325
325
|
|
|
326
326
|
this.update(options)
|
|
327
327
|
|
|
328
328
|
// Allow frameworks to hook into the router creation
|
|
329
|
-
this.options.
|
|
329
|
+
this.options.Router?.(this)
|
|
330
330
|
}
|
|
331
331
|
|
|
332
332
|
reset = () => {
|
|
@@ -378,15 +378,23 @@ export class Router<
|
|
|
378
378
|
>(
|
|
379
379
|
opts?: RouterOptions<TRouteConfig, TRouterContext>,
|
|
380
380
|
): Router<TRouteConfig, TAllRouteInfo, TRouterContext> => {
|
|
381
|
-
|
|
381
|
+
Object.assign(this.options, opts)
|
|
382
|
+
|
|
383
|
+
if (
|
|
384
|
+
!this.history ||
|
|
385
|
+
(this.options.history && this.options.history !== this.history)
|
|
386
|
+
) {
|
|
387
|
+
this.history =
|
|
388
|
+
this.options?.history ?? isServer
|
|
389
|
+
? createMemoryHistory()
|
|
390
|
+
: createBrowserHistory()!
|
|
391
|
+
|
|
382
392
|
this.store.setState((s) => {
|
|
383
393
|
s.latestLocation = this.#parseLocation()
|
|
384
394
|
s.currentLocation = s.latestLocation
|
|
385
395
|
})
|
|
386
396
|
}
|
|
387
397
|
|
|
388
|
-
Object.assign(this.options, opts)
|
|
389
|
-
|
|
390
398
|
const { basepath, routeConfig } = this.options
|
|
391
399
|
|
|
392
400
|
this.basepath = `/${trimPath(basepath ?? '') ?? ''}`
|
|
@@ -702,7 +710,7 @@ export class Router<
|
|
|
702
710
|
existingMatches.find((d) => d.id === matchId) ||
|
|
703
711
|
this.store.state.matchCache[matchId]?.match ||
|
|
704
712
|
new RouteMatch(this, foundRoute, {
|
|
705
|
-
matchId,
|
|
713
|
+
id: matchId,
|
|
706
714
|
params,
|
|
707
715
|
pathname: joinPaths([this.basepath, interpolatedPath]),
|
|
708
716
|
})
|
|
@@ -800,7 +808,12 @@ export class Router<
|
|
|
800
808
|
|
|
801
809
|
// TODO: batch requests when possible
|
|
802
810
|
|
|
803
|
-
|
|
811
|
+
const res = await this.options.fetchServerDataFn!({
|
|
812
|
+
router: this,
|
|
813
|
+
routeMatch,
|
|
814
|
+
})
|
|
815
|
+
|
|
816
|
+
return res
|
|
804
817
|
}
|
|
805
818
|
}
|
|
806
819
|
|
|
@@ -1067,7 +1080,7 @@ export class Router<
|
|
|
1067
1080
|
'lastUpdated',
|
|
1068
1081
|
]),
|
|
1069
1082
|
currentMatches: this.store.state.currentMatches.map((match) => ({
|
|
1070
|
-
|
|
1083
|
+
id: match.id,
|
|
1071
1084
|
state: {
|
|
1072
1085
|
...pick(match.store.state, [
|
|
1073
1086
|
'status',
|
|
@@ -1098,7 +1111,7 @@ export class Router<
|
|
|
1098
1111
|
currentMatches.forEach((match, index) => {
|
|
1099
1112
|
const dehydratedMatch = dehydratedRouter.state.currentMatches[index]
|
|
1100
1113
|
invariant(
|
|
1101
|
-
dehydratedMatch && dehydratedMatch.
|
|
1114
|
+
dehydratedMatch && dehydratedMatch.id === match.id,
|
|
1102
1115
|
'Oh no! There was a hydration mismatch when attempting to rethis.store the state of the router! 😬',
|
|
1103
1116
|
)
|
|
1104
1117
|
Object.assign(match, dehydratedMatch)
|
|
@@ -1339,7 +1352,7 @@ export class Router<
|
|
|
1339
1352
|
...next.state,
|
|
1340
1353
|
})
|
|
1341
1354
|
|
|
1342
|
-
this.load(this.#parseLocation(this.store.state.latestLocation))
|
|
1355
|
+
// this.load(this.#parseLocation(this.store.state.latestLocation))
|
|
1343
1356
|
|
|
1344
1357
|
return (this.navigationPromise = new Promise((resolve) => {
|
|
1345
1358
|
const previousNavigationResolve = this.resolveNavigation
|