@tanstack/react-router 1.44.5 → 1.45.0
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/useMatch.cjs
CHANGED
|
@@ -29,9 +29,12 @@ function useMatch(opts) {
|
|
|
29
29
|
(d) => opts.from ? opts.from === d.routeId : d.id === nearestMatchId
|
|
30
30
|
);
|
|
31
31
|
invariant(
|
|
32
|
-
match,
|
|
32
|
+
!((opts.shouldThrow ?? true) && !match),
|
|
33
33
|
`Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`
|
|
34
34
|
);
|
|
35
|
+
if (match === void 0) {
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
35
38
|
return opts.select ? opts.select(match) : match;
|
|
36
39
|
}
|
|
37
40
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMatch.cjs","sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useRouterState } from './useRouterState'\nimport { type RegisteredRouter } from './router'\nimport { type AnyRoute } from './route'\nimport { matchContext } from './matchContext'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { StrictOrFrom } from './utils'\n\nexport type UseMatchOptions<\n TFrom,\n TStrict extends boolean,\n TRouteMatch,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (match: TRouteMatch) => TSelected\n}\n\nexport function useMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>,\n TSelected = TRouteMatch,\n>(opts: UseMatchOptions<TFrom, TStrict, TRouteMatch, TSelected
|
|
1
|
+
{"version":3,"file":"useMatch.cjs","sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useRouterState } from './useRouterState'\nimport { type RegisteredRouter } from './router'\nimport { type AnyRoute } from './route'\nimport { matchContext } from './matchContext'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { StrictOrFrom } from './utils'\n\nexport type UseMatchOptions<\n TFrom,\n TStrict extends boolean,\n TRouteMatch,\n TSelected,\n TThrow extends boolean,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (match: TRouteMatch) => TSelected\n shouldThrow?: TThrow\n}\n\nexport function useMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>,\n TSelected = TRouteMatch,\n TThrow extends boolean = true,\n>(\n opts: UseMatchOptions<TFrom, TStrict, TRouteMatch, TSelected, TThrow>,\n): TThrow extends true ? TSelected : TSelected | undefined {\n const nearestMatchId = React.useContext(matchContext)\n\n const matchSelection = useRouterState({\n select: (state) => {\n const match = state.matches.find((d) =>\n opts.from ? opts.from === d.routeId : d.id === nearestMatchId,\n )\n invariant(\n !((opts.shouldThrow ?? true) && !match),\n `Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n\n if (match === undefined) {\n return undefined\n }\n\n return opts.select ? opts.select(match as any) : match\n },\n })\n\n return matchSelection as TSelected\n}\n"],"names":["React","matchContext","useRouterState"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqBO,SAAS,SAQd,MACyD;AACnD,QAAA,iBAAiBA,iBAAM,WAAWC,aAAY,YAAA;AAEpD,QAAM,iBAAiBC,eAAAA,eAAe;AAAA,IACpC,QAAQ,CAAC,UAAU;AACX,YAAA,QAAQ,MAAM,QAAQ;AAAA,QAAK,CAAC,MAChC,KAAK,OAAO,KAAK,SAAS,EAAE,UAAU,EAAE,OAAO;AAAA,MAAA;AAEjD;AAAA,QACE,GAAG,KAAK,eAAe,SAAS,CAAC;AAAA,QACjC,kBAAkB,KAAK,OAAO,yBAAyB,KAAK,IAAI,MAAM,kBAAkB;AAAA,MAAA;AAG1F,UAAI,UAAU,QAAW;AAChB,eAAA;AAAA,MACT;AAEA,aAAO,KAAK,SAAS,KAAK,OAAO,KAAY,IAAI;AAAA,IACnD;AAAA,EAAA,CACD;AAEM,SAAA;AACT;;"}
|
package/dist/cjs/useMatch.d.cts
CHANGED
|
@@ -4,7 +4,8 @@ import { MakeRouteMatch } from './Matches.cjs';
|
|
|
4
4
|
import { RouteIds } from './routeInfo.cjs';
|
|
5
5
|
import { StrictOrFrom } from './utils.cjs';
|
|
6
6
|
|
|
7
|
-
export type UseMatchOptions<TFrom, TStrict extends boolean, TRouteMatch, TSelected> = StrictOrFrom<TFrom, TStrict> & {
|
|
7
|
+
export type UseMatchOptions<TFrom, TStrict extends boolean, TRouteMatch, TSelected, TThrow extends boolean> = StrictOrFrom<TFrom, TStrict> & {
|
|
8
8
|
select?: (match: TRouteMatch) => TSelected;
|
|
9
|
+
shouldThrow?: TThrow;
|
|
9
10
|
};
|
|
10
|
-
export declare function useMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>, TSelected = TRouteMatch>(opts: UseMatchOptions<TFrom, TStrict, TRouteMatch, TSelected>): TSelected;
|
|
11
|
+
export declare function useMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>, TSelected = TRouteMatch, TThrow extends boolean = true>(opts: UseMatchOptions<TFrom, TStrict, TRouteMatch, TSelected, TThrow>): TThrow extends true ? TSelected : TSelected | undefined;
|
package/dist/esm/useMatch.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { MakeRouteMatch } from './Matches.js';
|
|
|
4
4
|
import { RouteIds } from './routeInfo.js';
|
|
5
5
|
import { StrictOrFrom } from './utils.js';
|
|
6
6
|
|
|
7
|
-
export type UseMatchOptions<TFrom, TStrict extends boolean, TRouteMatch, TSelected> = StrictOrFrom<TFrom, TStrict> & {
|
|
7
|
+
export type UseMatchOptions<TFrom, TStrict extends boolean, TRouteMatch, TSelected, TThrow extends boolean> = StrictOrFrom<TFrom, TStrict> & {
|
|
8
8
|
select?: (match: TRouteMatch) => TSelected;
|
|
9
|
+
shouldThrow?: TThrow;
|
|
9
10
|
};
|
|
10
|
-
export declare function useMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>, TSelected = TRouteMatch>(opts: UseMatchOptions<TFrom, TStrict, TRouteMatch, TSelected>): TSelected;
|
|
11
|
+
export declare function useMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>, TSelected = TRouteMatch, TThrow extends boolean = true>(opts: UseMatchOptions<TFrom, TStrict, TRouteMatch, TSelected, TThrow>): TThrow extends true ? TSelected : TSelected | undefined;
|
package/dist/esm/useMatch.js
CHANGED
|
@@ -10,9 +10,12 @@ function useMatch(opts) {
|
|
|
10
10
|
(d) => opts.from ? opts.from === d.routeId : d.id === nearestMatchId
|
|
11
11
|
);
|
|
12
12
|
invariant(
|
|
13
|
-
match,
|
|
13
|
+
!((opts.shouldThrow ?? true) && !match),
|
|
14
14
|
`Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`
|
|
15
15
|
);
|
|
16
|
+
if (match === void 0) {
|
|
17
|
+
return void 0;
|
|
18
|
+
}
|
|
16
19
|
return opts.select ? opts.select(match) : match;
|
|
17
20
|
}
|
|
18
21
|
});
|
package/dist/esm/useMatch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMatch.js","sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useRouterState } from './useRouterState'\nimport { type RegisteredRouter } from './router'\nimport { type AnyRoute } from './route'\nimport { matchContext } from './matchContext'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { StrictOrFrom } from './utils'\n\nexport type UseMatchOptions<\n TFrom,\n TStrict extends boolean,\n TRouteMatch,\n TSelected,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (match: TRouteMatch) => TSelected\n}\n\nexport function useMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>,\n TSelected = TRouteMatch,\n>(opts: UseMatchOptions<TFrom, TStrict, TRouteMatch, TSelected
|
|
1
|
+
{"version":3,"file":"useMatch.js","sources":["../../src/useMatch.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport { useRouterState } from './useRouterState'\nimport { type RegisteredRouter } from './router'\nimport { type AnyRoute } from './route'\nimport { matchContext } from './matchContext'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RouteIds } from './routeInfo'\nimport type { StrictOrFrom } from './utils'\n\nexport type UseMatchOptions<\n TFrom,\n TStrict extends boolean,\n TRouteMatch,\n TSelected,\n TThrow extends boolean,\n> = StrictOrFrom<TFrom, TStrict> & {\n select?: (match: TRouteMatch) => TSelected\n shouldThrow?: TThrow\n}\n\nexport function useMatch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TStrict extends boolean = true,\n TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>,\n TSelected = TRouteMatch,\n TThrow extends boolean = true,\n>(\n opts: UseMatchOptions<TFrom, TStrict, TRouteMatch, TSelected, TThrow>,\n): TThrow extends true ? TSelected : TSelected | undefined {\n const nearestMatchId = React.useContext(matchContext)\n\n const matchSelection = useRouterState({\n select: (state) => {\n const match = state.matches.find((d) =>\n opts.from ? opts.from === d.routeId : d.id === nearestMatchId,\n )\n invariant(\n !((opts.shouldThrow ?? true) && !match),\n `Could not find ${opts.from ? `an active match from \"${opts.from}\"` : 'a nearest match!'}`,\n )\n\n if (match === undefined) {\n return undefined\n }\n\n return opts.select ? opts.select(match as any) : match\n },\n })\n\n return matchSelection as TSelected\n}\n"],"names":[],"mappings":";;;;AAqBO,SAAS,SAQd,MACyD;AACnD,QAAA,iBAAiB,MAAM,WAAW,YAAY;AAEpD,QAAM,iBAAiB,eAAe;AAAA,IACpC,QAAQ,CAAC,UAAU;AACX,YAAA,QAAQ,MAAM,QAAQ;AAAA,QAAK,CAAC,MAChC,KAAK,OAAO,KAAK,SAAS,EAAE,UAAU,EAAE,OAAO;AAAA,MAAA;AAEjD;AAAA,QACE,GAAG,KAAK,eAAe,SAAS,CAAC;AAAA,QACjC,kBAAkB,KAAK,OAAO,yBAAyB,KAAK,IAAI,MAAM,kBAAkB;AAAA,MAAA;AAG1F,UAAI,UAAU,QAAW;AAChB,eAAA;AAAA,MACT;AAEA,aAAO,KAAK,SAAS,KAAK,OAAO,KAAY,IAAI;AAAA,IACnD;AAAA,EAAA,CACD;AAEM,SAAA;AACT;"}
|
package/package.json
CHANGED
package/src/useMatch.tsx
CHANGED
|
@@ -13,8 +13,10 @@ export type UseMatchOptions<
|
|
|
13
13
|
TStrict extends boolean,
|
|
14
14
|
TRouteMatch,
|
|
15
15
|
TSelected,
|
|
16
|
+
TThrow extends boolean,
|
|
16
17
|
> = StrictOrFrom<TFrom, TStrict> & {
|
|
17
18
|
select?: (match: TRouteMatch) => TSelected
|
|
19
|
+
shouldThrow?: TThrow
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
export function useMatch<
|
|
@@ -23,7 +25,10 @@ export function useMatch<
|
|
|
23
25
|
TStrict extends boolean = true,
|
|
24
26
|
TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>,
|
|
25
27
|
TSelected = TRouteMatch,
|
|
26
|
-
|
|
28
|
+
TThrow extends boolean = true,
|
|
29
|
+
>(
|
|
30
|
+
opts: UseMatchOptions<TFrom, TStrict, TRouteMatch, TSelected, TThrow>,
|
|
31
|
+
): TThrow extends true ? TSelected : TSelected | undefined {
|
|
27
32
|
const nearestMatchId = React.useContext(matchContext)
|
|
28
33
|
|
|
29
34
|
const matchSelection = useRouterState({
|
|
@@ -31,12 +36,15 @@ export function useMatch<
|
|
|
31
36
|
const match = state.matches.find((d) =>
|
|
32
37
|
opts.from ? opts.from === d.routeId : d.id === nearestMatchId,
|
|
33
38
|
)
|
|
34
|
-
|
|
35
39
|
invariant(
|
|
36
|
-
match,
|
|
40
|
+
!((opts.shouldThrow ?? true) && !match),
|
|
37
41
|
`Could not find ${opts.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`,
|
|
38
42
|
)
|
|
39
43
|
|
|
44
|
+
if (match === undefined) {
|
|
45
|
+
return undefined
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
return opts.select ? opts.select(match as any) : match
|
|
41
49
|
},
|
|
42
50
|
})
|