@tanstack/react-router 1.28.3 → 1.28.4
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/dist/cjs/router.cjs +36 -43
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/esm/router.js +36 -43
- package/dist/esm/router.js.map +1 -1
- package/package.json +2 -2
- package/src/router.ts +34 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
|
-
"version": "1.28.
|
|
3
|
+
"version": "1.28.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"clean": "rimraf ./dist && rimraf ./coverage",
|
|
71
71
|
"test:eslint": "eslint --ext .ts,.tsx ./src",
|
|
72
72
|
"test:types": "tsc --noEmit",
|
|
73
|
-
"test:unit": "vitest --typecheck
|
|
73
|
+
"test:unit": "vitest --typecheck",
|
|
74
74
|
"test:unit:dev": "pnpm run test:unit --watch",
|
|
75
75
|
"test:build": "publint --strict",
|
|
76
76
|
"build": "vite build"
|
package/src/router.ts
CHANGED
|
@@ -1206,7 +1206,15 @@ export class Router<
|
|
|
1206
1206
|
return updated
|
|
1207
1207
|
}
|
|
1208
1208
|
|
|
1209
|
-
|
|
1209
|
+
try {
|
|
1210
|
+
await new Promise<void>((resolveAll, rejectAll) => {
|
|
1211
|
+
;(async () => {
|
|
1212
|
+
try {
|
|
1213
|
+
const handleRedirectAndNotFound = (
|
|
1214
|
+
match: AnyRouteMatch,
|
|
1215
|
+
err: any,
|
|
1216
|
+
) => {
|
|
1217
|
+
if (isRedirect(err) || isNotFound(err)) {
|
|
1210
1218
|
updateMatch(match.id, (prev) => ({
|
|
1211
1219
|
...prev,
|
|
1212
1220
|
status: isRedirect(err)
|
|
@@ -1218,17 +1226,25 @@ export class Router<
|
|
|
1218
1226
|
error: err,
|
|
1219
1227
|
}))
|
|
1220
1228
|
|
|
1221
|
-
|
|
1222
|
-
|
|
1229
|
+
if (!(err as any).routeId) {
|
|
1230
|
+
;(err as any).routeId = match.routeId
|
|
1223
1231
|
}
|
|
1224
1232
|
|
|
1233
|
+
if (isRedirect(err)) {
|
|
1234
|
+
const redirect = this.resolveRedirect(err)
|
|
1235
|
+
|
|
1236
|
+
if (!preload && !this.isServer) {
|
|
1237
|
+
this.navigate({ ...(redirect as any), replace: true })
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
throw redirect
|
|
1241
|
+
} else if (isNotFound(err)) {
|
|
1242
|
+
if (!preload) this.handleNotFound(matches, err)
|
|
1225
1243
|
throw err
|
|
1226
1244
|
}
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1227
1247
|
|
|
1228
|
-
try {
|
|
1229
|
-
await new Promise<void>((resolveAll, rejectAll) => {
|
|
1230
|
-
;(async () => {
|
|
1231
|
-
try {
|
|
1232
1248
|
// Check each match middleware to see if the route can be accessed
|
|
1233
1249
|
// eslint-disable-next-line prefer-const
|
|
1234
1250
|
for (let [index, match] of matches.entries()) {
|
|
@@ -1236,22 +1252,16 @@ export class Router<
|
|
|
1236
1252
|
const route = this.looseRoutesById[match.routeId]!
|
|
1237
1253
|
const abortController = new AbortController()
|
|
1238
1254
|
|
|
1239
|
-
const handleSerialError = (err: any,
|
|
1240
|
-
err.routerCode =
|
|
1255
|
+
const handleSerialError = (err: any, routerCode: string) => {
|
|
1256
|
+
err.routerCode = routerCode
|
|
1241
1257
|
firstBadMatchIndex = firstBadMatchIndex ?? index
|
|
1242
|
-
|
|
1243
|
-
if (isRedirect(err) || isNotFound(err)) {
|
|
1244
|
-
handleMatchSpecialError(match, err)
|
|
1245
|
-
}
|
|
1258
|
+
handleRedirectAndNotFound(match, err)
|
|
1246
1259
|
|
|
1247
1260
|
try {
|
|
1248
1261
|
route.options.onError?.(err)
|
|
1249
1262
|
} catch (errorHandlerErr) {
|
|
1250
1263
|
err = errorHandlerErr
|
|
1251
|
-
|
|
1252
|
-
if (isRedirect(err) || isNotFound(err)) {
|
|
1253
|
-
handleMatchSpecialError(match, errorHandlerErr)
|
|
1254
|
-
}
|
|
1264
|
+
handleRedirectAndNotFound(match, err)
|
|
1255
1265
|
}
|
|
1256
1266
|
|
|
1257
1267
|
matches[index] = match = {
|
|
@@ -1356,12 +1366,6 @@ export class Router<
|
|
|
1356
1366
|
const parentMatchPromise = matchPromises[index - 1]
|
|
1357
1367
|
const route = this.looseRoutesById[match.routeId]!
|
|
1358
1368
|
|
|
1359
|
-
const handleError = (err: any) => {
|
|
1360
|
-
if (isRedirect(err) || isNotFound(err)) {
|
|
1361
|
-
handleMatchSpecialError(match, err)
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
|
|
1365
1369
|
const loaderContext: LoaderFnContext = {
|
|
1366
1370
|
params: match.params,
|
|
1367
1371
|
deps: match.loaderDeps,
|
|
@@ -1469,7 +1473,7 @@ export class Router<
|
|
|
1469
1473
|
if ((latestPromise = checkLatest()))
|
|
1470
1474
|
return await latestPromise
|
|
1471
1475
|
|
|
1472
|
-
|
|
1476
|
+
handleRedirectAndNotFound(match, loaderData)
|
|
1473
1477
|
|
|
1474
1478
|
if ((latestPromise = checkLatest()))
|
|
1475
1479
|
return await latestPromise
|
|
@@ -1506,13 +1510,13 @@ export class Router<
|
|
|
1506
1510
|
if ((latestPromise = checkLatest()))
|
|
1507
1511
|
return await latestPromise
|
|
1508
1512
|
|
|
1509
|
-
|
|
1513
|
+
handleRedirectAndNotFound(match, e)
|
|
1510
1514
|
|
|
1511
1515
|
try {
|
|
1512
1516
|
route.options.onError?.(e)
|
|
1513
1517
|
} catch (onErrorError) {
|
|
1514
1518
|
error = onErrorError
|
|
1515
|
-
|
|
1519
|
+
handleRedirectAndNotFound(match, onErrorError)
|
|
1516
1520
|
}
|
|
1517
1521
|
|
|
1518
1522
|
matches[index] = match = updateMatch(match.id, (prev) => ({
|
|
@@ -1561,27 +1565,13 @@ export class Router<
|
|
|
1561
1565
|
!this.state.matches.find((d) => d.id === match.id),
|
|
1562
1566
|
}
|
|
1563
1567
|
|
|
1564
|
-
const
|
|
1568
|
+
const fetchWithRedirectAndNotFound = async () => {
|
|
1565
1569
|
try {
|
|
1566
1570
|
await fetch()
|
|
1567
1571
|
} catch (err) {
|
|
1568
1572
|
if ((latestPromise = checkLatest()))
|
|
1569
1573
|
return await latestPromise
|
|
1570
|
-
|
|
1571
|
-
if (isRedirect(err)) {
|
|
1572
|
-
const redirect = this.resolveRedirect(err)
|
|
1573
|
-
|
|
1574
|
-
if (!preload && !this.isServer) {
|
|
1575
|
-
this.navigate({ ...(redirect as any), replace: true })
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
throw redirect
|
|
1579
|
-
} else if (isNotFound(err)) {
|
|
1580
|
-
if (!preload) this.handleNotFound(matches, err)
|
|
1581
|
-
throw err
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
handleError(err)
|
|
1574
|
+
handleRedirectAndNotFound(match, err)
|
|
1585
1575
|
}
|
|
1586
1576
|
}
|
|
1587
1577
|
|
|
@@ -1590,12 +1580,12 @@ export class Router<
|
|
|
1590
1580
|
match.status === 'success' &&
|
|
1591
1581
|
(match.invalid || (shouldReload ?? age > staleAge))
|
|
1592
1582
|
) {
|
|
1593
|
-
|
|
1583
|
+
fetchWithRedirectAndNotFound()
|
|
1594
1584
|
return
|
|
1595
1585
|
}
|
|
1596
1586
|
|
|
1597
1587
|
if (match.status !== 'success') {
|
|
1598
|
-
await
|
|
1588
|
+
await fetchWithRedirectAndNotFound()
|
|
1599
1589
|
}
|
|
1600
1590
|
}),
|
|
1601
1591
|
)
|