@tanstack/react-router 1.131.28 → 1.131.31
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/link.cjs +1 -8
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/useNavigate.cjs +2 -6
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/esm/link.js +1 -8
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/useNavigate.js +2 -6
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/llms/rules/guide.d.ts +1 -1
- package/dist/llms/rules/guide.js +2 -2
- package/package.json +2 -2
- package/src/link.tsx +1 -11
- package/src/useNavigate.tsx +2 -8
- package/dist/cjs/useActiveLocation.cjs +0 -39
- package/dist/cjs/useActiveLocation.cjs.map +0 -1
- package/dist/cjs/useActiveLocation.d.cts +0 -7
- package/dist/esm/useActiveLocation.d.ts +0 -7
- package/dist/esm/useActiveLocation.js +0 -39
- package/dist/esm/useActiveLocation.js.map +0 -1
- package/src/useActiveLocation.ts +0 -57
package/dist/llms/rules/guide.js
CHANGED
|
@@ -2256,7 +2256,7 @@ Literally any library that **can return a promise and read/write data** can be i
|
|
|
2256
2256
|
|
|
2257
2257
|
## Using Loaders to ensure data is loaded
|
|
2258
2258
|
|
|
2259
|
-
The easiest way to
|
|
2259
|
+
The easiest way to integrate external caching/data library into Router is to use \`route.loader\`s to ensure that the data required inside of a route has been loaded and is ready to be displayed.
|
|
2260
2260
|
|
|
2261
2261
|
> ⚠️ BUT WHY? It's very important to preload your critical render data in the loader for a few reasons:
|
|
2262
2262
|
>
|
|
@@ -2324,7 +2324,7 @@ export const Route = createFileRoute('/posts')({
|
|
|
2324
2324
|
|
|
2325
2325
|
### Error handling with TanStack Query
|
|
2326
2326
|
|
|
2327
|
-
When an error occurs while using \`suspense\` with \`TanStack Query\`, you
|
|
2327
|
+
When an error occurs while using \`suspense\` with \`TanStack Query\`, you need to let queries know that you want to try again when re-rendering. This can be done by using the \`reset\` function provided by the \`useQueryErrorResetBoundary\` hook. You can invoke this function in an effect as soon as the error component mounts. This will make sure that the query is reset and will try to fetch data again when the route component is rendered again. This will also cover cases where users navigate away from the route instead of clicking the \`retry\` button.
|
|
2328
2328
|
|
|
2329
2329
|
\`\`\`tsx
|
|
2330
2330
|
export const Route = createFileRoute('/')({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
|
-
"version": "1.131.
|
|
3
|
+
"version": "1.131.31",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"tiny-invariant": "^1.3.3",
|
|
81
81
|
"tiny-warning": "^1.0.3",
|
|
82
82
|
"@tanstack/history": "1.131.2",
|
|
83
|
-
"@tanstack/router-core": "1.131.
|
|
83
|
+
"@tanstack/router-core": "1.131.30"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@testing-library/jest-dom": "^6.6.3",
|
package/src/link.tsx
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
preloadWarning,
|
|
8
8
|
removeTrailingSlash,
|
|
9
9
|
} from '@tanstack/router-core'
|
|
10
|
-
import { useActiveLocation } from './useActiveLocation'
|
|
11
10
|
import { useRouterState } from './useRouterState'
|
|
12
11
|
import { useRouter } from './useRouter'
|
|
13
12
|
|
|
@@ -99,15 +98,7 @@ export function useLinkProps<
|
|
|
99
98
|
structuralSharing: true as any,
|
|
100
99
|
})
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
const routerLocation = useRouterState({
|
|
104
|
-
select: (s) => s.location,
|
|
105
|
-
structuralSharing: true as any,
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
const { getFromPath } = useActiveLocation()
|
|
109
|
-
|
|
110
|
-
const from = getFromPath(options.from)
|
|
101
|
+
const from = options.from
|
|
111
102
|
|
|
112
103
|
const _options = React.useMemo(
|
|
113
104
|
() => {
|
|
@@ -116,7 +107,6 @@ export function useLinkProps<
|
|
|
116
107
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
117
108
|
[
|
|
118
109
|
router,
|
|
119
|
-
routerLocation,
|
|
120
110
|
currentSearch,
|
|
121
111
|
from,
|
|
122
112
|
options._fromLocation,
|
package/src/useNavigate.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { useRouter } from './useRouter'
|
|
3
|
-
import { useActiveLocation } from './useActiveLocation'
|
|
4
3
|
import type {
|
|
5
4
|
AnyRouter,
|
|
6
5
|
FromPathOption,
|
|
@@ -17,19 +16,14 @@ export function useNavigate<
|
|
|
17
16
|
}): UseNavigateResult<TDefaultFrom> {
|
|
18
17
|
const router = useRouter()
|
|
19
18
|
|
|
20
|
-
const { getFromPath, activeLocation } = useActiveLocation()
|
|
21
|
-
|
|
22
19
|
return React.useCallback(
|
|
23
20
|
(options: NavigateOptions) => {
|
|
24
|
-
const from = getFromPath(options.from ?? _defaultOpts?.from)
|
|
25
|
-
|
|
26
21
|
return router.navigate({
|
|
27
22
|
...options,
|
|
28
|
-
from,
|
|
23
|
+
from: options.from ?? _defaultOpts?.from,
|
|
29
24
|
})
|
|
30
25
|
},
|
|
31
|
-
|
|
32
|
-
[_defaultOpts?.from, router, getFromPath, activeLocation],
|
|
26
|
+
[_defaultOpts?.from, router],
|
|
33
27
|
) as UseNavigateResult<TDefaultFrom>
|
|
34
28
|
}
|
|
35
29
|
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const routerCore = require("@tanstack/router-core");
|
|
4
|
-
const React = require("react");
|
|
5
|
-
const useRouter = require("./useRouter.cjs");
|
|
6
|
-
const useMatch = require("./useMatch.cjs");
|
|
7
|
-
const useRouterState = require("./useRouterState.cjs");
|
|
8
|
-
const useActiveLocation = (location) => {
|
|
9
|
-
const router = useRouter.useRouter();
|
|
10
|
-
const routerLocation = useRouterState.useRouterState({ select: (state) => state.location });
|
|
11
|
-
const [activeLocation, setActiveLocation] = React.useState(
|
|
12
|
-
routerLocation
|
|
13
|
-
);
|
|
14
|
-
const [customActiveLocation, setCustomActiveLocation] = React.useState(location);
|
|
15
|
-
React.useEffect(() => {
|
|
16
|
-
setActiveLocation(customActiveLocation ?? routerLocation);
|
|
17
|
-
}, [routerLocation, customActiveLocation]);
|
|
18
|
-
const matchIndex = useMatch.useMatch({
|
|
19
|
-
strict: false,
|
|
20
|
-
select: (match) => match.index
|
|
21
|
-
});
|
|
22
|
-
const getFromPath = React.useCallback(
|
|
23
|
-
(from) => {
|
|
24
|
-
const activeLocationMatches = router.matchRoutes(activeLocation, {
|
|
25
|
-
_buildLocation: false
|
|
26
|
-
});
|
|
27
|
-
const activeLocationMatch = routerCore.last(activeLocationMatches);
|
|
28
|
-
return from ?? (activeLocationMatch == null ? void 0 : activeLocationMatch.fullPath) ?? router.state.matches[matchIndex].fullPath;
|
|
29
|
-
},
|
|
30
|
-
[activeLocation, matchIndex, router]
|
|
31
|
-
);
|
|
32
|
-
return {
|
|
33
|
-
activeLocation,
|
|
34
|
-
getFromPath,
|
|
35
|
-
setActiveLocation: setCustomActiveLocation
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
exports.useActiveLocation = useActiveLocation;
|
|
39
|
-
//# sourceMappingURL=useActiveLocation.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveLocation.cjs","sources":["../../src/useActiveLocation.ts"],"sourcesContent":["import { last } from '@tanstack/router-core'\nimport { useCallback, useEffect, useState } from 'react'\nimport { useRouter } from './useRouter'\nimport { useMatch } from './useMatch'\nimport { useRouterState } from './useRouterState'\nimport type { ParsedLocation } from '@tanstack/router-core'\n\nexport type UseActiveLocationResult = {\n activeLocation: ParsedLocation\n getFromPath: (from?: string) => string\n setActiveLocation: (location?: ParsedLocation) => void\n}\n\nexport const useActiveLocation = (\n location?: ParsedLocation,\n): UseActiveLocationResult => {\n const router = useRouter()\n const routerLocation = useRouterState({ select: (state) => state.location })\n const [activeLocation, setActiveLocation] = useState<ParsedLocation>(\n location ?? routerLocation,\n )\n const [customActiveLocation, setCustomActiveLocation] = useState<\n ParsedLocation | undefined\n >(location)\n\n useEffect(() => {\n setActiveLocation(customActiveLocation ?? routerLocation)\n }, [routerLocation, customActiveLocation])\n\n const matchIndex = useMatch({\n strict: false,\n select: (match) => match.index,\n })\n\n const getFromPath = useCallback(\n (from?: string) => {\n const activeLocationMatches = router.matchRoutes(activeLocation, {\n _buildLocation: false,\n })\n\n const activeLocationMatch = last(activeLocationMatches)\n\n return (\n from ??\n activeLocationMatch?.fullPath ??\n router.state.matches[matchIndex]!.fullPath\n )\n },\n [activeLocation, matchIndex, router],\n )\n\n return {\n activeLocation,\n getFromPath,\n setActiveLocation: setCustomActiveLocation,\n }\n}\n"],"names":["useRouter","useRouterState","useState","useEffect","useMatch","useCallback","last"],"mappings":";;;;;;;AAaa,MAAA,oBAAoB,CAC/B,aAC4B;AAC5B,QAAM,SAASA,UAAAA,UAAU;AACnB,QAAA,iBAAiBC,eAAAA,eAAe,EAAE,QAAQ,CAAC,UAAU,MAAM,UAAU;AACrE,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,MAAA;AAAA,IAC9B;AAAA,EACd;AACA,QAAM,CAAC,sBAAsB,uBAAuB,IAAIA,MAAAA,SAEtD,QAAQ;AAEVC,QAAAA,UAAU,MAAM;AACd,sBAAkB,wBAAwB,cAAc;AAAA,EAAA,GACvD,CAAC,gBAAgB,oBAAoB,CAAC;AAEzC,QAAM,aAAaC,SAAAA,SAAS;AAAA,IAC1B,QAAQ;AAAA,IACR,QAAQ,CAAC,UAAU,MAAM;AAAA,EAAA,CAC1B;AAED,QAAM,cAAcC,MAAA;AAAA,IAClB,CAAC,SAAkB;AACX,YAAA,wBAAwB,OAAO,YAAY,gBAAgB;AAAA,QAC/D,gBAAgB;AAAA,MAAA,CACjB;AAEK,YAAA,sBAAsBC,gBAAK,qBAAqB;AAEtD,aACE,SACA,2DAAqB,aACrB,OAAO,MAAM,QAAQ,UAAU,EAAG;AAAA,IAEtC;AAAA,IACA,CAAC,gBAAgB,YAAY,MAAM;AAAA,EACrC;AAEO,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,EACrB;AACF;;"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ParsedLocation } from '@tanstack/router-core';
|
|
2
|
-
export type UseActiveLocationResult = {
|
|
3
|
-
activeLocation: ParsedLocation;
|
|
4
|
-
getFromPath: (from?: string) => string;
|
|
5
|
-
setActiveLocation: (location?: ParsedLocation) => void;
|
|
6
|
-
};
|
|
7
|
-
export declare const useActiveLocation: (location?: ParsedLocation) => UseActiveLocationResult;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ParsedLocation } from '@tanstack/router-core';
|
|
2
|
-
export type UseActiveLocationResult = {
|
|
3
|
-
activeLocation: ParsedLocation;
|
|
4
|
-
getFromPath: (from?: string) => string;
|
|
5
|
-
setActiveLocation: (location?: ParsedLocation) => void;
|
|
6
|
-
};
|
|
7
|
-
export declare const useActiveLocation: (location?: ParsedLocation) => UseActiveLocationResult;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { last } from "@tanstack/router-core";
|
|
2
|
-
import { useState, useEffect, useCallback } from "react";
|
|
3
|
-
import { useRouter } from "./useRouter.js";
|
|
4
|
-
import { useMatch } from "./useMatch.js";
|
|
5
|
-
import { useRouterState } from "./useRouterState.js";
|
|
6
|
-
const useActiveLocation = (location) => {
|
|
7
|
-
const router = useRouter();
|
|
8
|
-
const routerLocation = useRouterState({ select: (state) => state.location });
|
|
9
|
-
const [activeLocation, setActiveLocation] = useState(
|
|
10
|
-
routerLocation
|
|
11
|
-
);
|
|
12
|
-
const [customActiveLocation, setCustomActiveLocation] = useState(location);
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
setActiveLocation(customActiveLocation ?? routerLocation);
|
|
15
|
-
}, [routerLocation, customActiveLocation]);
|
|
16
|
-
const matchIndex = useMatch({
|
|
17
|
-
strict: false,
|
|
18
|
-
select: (match) => match.index
|
|
19
|
-
});
|
|
20
|
-
const getFromPath = useCallback(
|
|
21
|
-
(from) => {
|
|
22
|
-
const activeLocationMatches = router.matchRoutes(activeLocation, {
|
|
23
|
-
_buildLocation: false
|
|
24
|
-
});
|
|
25
|
-
const activeLocationMatch = last(activeLocationMatches);
|
|
26
|
-
return from ?? (activeLocationMatch == null ? void 0 : activeLocationMatch.fullPath) ?? router.state.matches[matchIndex].fullPath;
|
|
27
|
-
},
|
|
28
|
-
[activeLocation, matchIndex, router]
|
|
29
|
-
);
|
|
30
|
-
return {
|
|
31
|
-
activeLocation,
|
|
32
|
-
getFromPath,
|
|
33
|
-
setActiveLocation: setCustomActiveLocation
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
export {
|
|
37
|
-
useActiveLocation
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=useActiveLocation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveLocation.js","sources":["../../src/useActiveLocation.ts"],"sourcesContent":["import { last } from '@tanstack/router-core'\nimport { useCallback, useEffect, useState } from 'react'\nimport { useRouter } from './useRouter'\nimport { useMatch } from './useMatch'\nimport { useRouterState } from './useRouterState'\nimport type { ParsedLocation } from '@tanstack/router-core'\n\nexport type UseActiveLocationResult = {\n activeLocation: ParsedLocation\n getFromPath: (from?: string) => string\n setActiveLocation: (location?: ParsedLocation) => void\n}\n\nexport const useActiveLocation = (\n location?: ParsedLocation,\n): UseActiveLocationResult => {\n const router = useRouter()\n const routerLocation = useRouterState({ select: (state) => state.location })\n const [activeLocation, setActiveLocation] = useState<ParsedLocation>(\n location ?? routerLocation,\n )\n const [customActiveLocation, setCustomActiveLocation] = useState<\n ParsedLocation | undefined\n >(location)\n\n useEffect(() => {\n setActiveLocation(customActiveLocation ?? routerLocation)\n }, [routerLocation, customActiveLocation])\n\n const matchIndex = useMatch({\n strict: false,\n select: (match) => match.index,\n })\n\n const getFromPath = useCallback(\n (from?: string) => {\n const activeLocationMatches = router.matchRoutes(activeLocation, {\n _buildLocation: false,\n })\n\n const activeLocationMatch = last(activeLocationMatches)\n\n return (\n from ??\n activeLocationMatch?.fullPath ??\n router.state.matches[matchIndex]!.fullPath\n )\n },\n [activeLocation, matchIndex, router],\n )\n\n return {\n activeLocation,\n getFromPath,\n setActiveLocation: setCustomActiveLocation,\n }\n}\n"],"names":[],"mappings":";;;;;AAaa,MAAA,oBAAoB,CAC/B,aAC4B;AAC5B,QAAM,SAAS,UAAU;AACnB,QAAA,iBAAiB,eAAe,EAAE,QAAQ,CAAC,UAAU,MAAM,UAAU;AACrE,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC9B;AAAA,EACd;AACA,QAAM,CAAC,sBAAsB,uBAAuB,IAAI,SAEtD,QAAQ;AAEV,YAAU,MAAM;AACd,sBAAkB,wBAAwB,cAAc;AAAA,EAAA,GACvD,CAAC,gBAAgB,oBAAoB,CAAC;AAEzC,QAAM,aAAa,SAAS;AAAA,IAC1B,QAAQ;AAAA,IACR,QAAQ,CAAC,UAAU,MAAM;AAAA,EAAA,CAC1B;AAED,QAAM,cAAc;AAAA,IAClB,CAAC,SAAkB;AACX,YAAA,wBAAwB,OAAO,YAAY,gBAAgB;AAAA,QAC/D,gBAAgB;AAAA,MAAA,CACjB;AAEK,YAAA,sBAAsB,KAAK,qBAAqB;AAEtD,aACE,SACA,2DAAqB,aACrB,OAAO,MAAM,QAAQ,UAAU,EAAG;AAAA,IAEtC;AAAA,IACA,CAAC,gBAAgB,YAAY,MAAM;AAAA,EACrC;AAEO,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,EACrB;AACF;"}
|
package/src/useActiveLocation.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { last } from '@tanstack/router-core'
|
|
2
|
-
import { useCallback, useEffect, useState } from 'react'
|
|
3
|
-
import { useRouter } from './useRouter'
|
|
4
|
-
import { useMatch } from './useMatch'
|
|
5
|
-
import { useRouterState } from './useRouterState'
|
|
6
|
-
import type { ParsedLocation } from '@tanstack/router-core'
|
|
7
|
-
|
|
8
|
-
export type UseActiveLocationResult = {
|
|
9
|
-
activeLocation: ParsedLocation
|
|
10
|
-
getFromPath: (from?: string) => string
|
|
11
|
-
setActiveLocation: (location?: ParsedLocation) => void
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const useActiveLocation = (
|
|
15
|
-
location?: ParsedLocation,
|
|
16
|
-
): UseActiveLocationResult => {
|
|
17
|
-
const router = useRouter()
|
|
18
|
-
const routerLocation = useRouterState({ select: (state) => state.location })
|
|
19
|
-
const [activeLocation, setActiveLocation] = useState<ParsedLocation>(
|
|
20
|
-
location ?? routerLocation,
|
|
21
|
-
)
|
|
22
|
-
const [customActiveLocation, setCustomActiveLocation] = useState<
|
|
23
|
-
ParsedLocation | undefined
|
|
24
|
-
>(location)
|
|
25
|
-
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
setActiveLocation(customActiveLocation ?? routerLocation)
|
|
28
|
-
}, [routerLocation, customActiveLocation])
|
|
29
|
-
|
|
30
|
-
const matchIndex = useMatch({
|
|
31
|
-
strict: false,
|
|
32
|
-
select: (match) => match.index,
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
const getFromPath = useCallback(
|
|
36
|
-
(from?: string) => {
|
|
37
|
-
const activeLocationMatches = router.matchRoutes(activeLocation, {
|
|
38
|
-
_buildLocation: false,
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
const activeLocationMatch = last(activeLocationMatches)
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
from ??
|
|
45
|
-
activeLocationMatch?.fullPath ??
|
|
46
|
-
router.state.matches[matchIndex]!.fullPath
|
|
47
|
-
)
|
|
48
|
-
},
|
|
49
|
-
[activeLocation, matchIndex, router],
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
activeLocation,
|
|
54
|
-
getFromPath,
|
|
55
|
-
setActiveLocation: setCustomActiveLocation,
|
|
56
|
-
}
|
|
57
|
-
}
|