@tanstack/react-router 1.0.2 → 1.0.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/build/cjs/Matches.js +1 -0
- package/build/cjs/Matches.js.map +1 -1
- package/build/cjs/index.js +1 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/useParams.js +2 -1
- package/build/cjs/useParams.js.map +1 -1
- package/build/esm/index.js +2 -2
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +359 -353
- package/build/types/Matches.d.ts +2 -1
- package/build/umd/index.development.js +9 -9
- 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 +1 -1
- package/src/useParams.tsx +2 -1
package/build/types/Matches.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { ResolveRelativePath, ToOptions } from './link';
|
|
3
3
|
import { AnyRoute, ReactNode } from './route';
|
|
4
4
|
import { FullSearchSchema, ParseRoute, RouteById, RouteByPath, RouteIds, RoutePaths } from './routeInfo';
|
|
5
|
-
import { RegisteredRouter } from './router';
|
|
5
|
+
import { RegisteredRouter, RouterState } from './router';
|
|
6
6
|
import { NoInfer, StrictOrFrom } from './utils';
|
|
7
7
|
export declare const matchContext: React.Context<string | undefined>;
|
|
8
8
|
export interface RouteMatch<TRouteTree extends AnyRoute = AnyRoute, TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id']> {
|
|
@@ -47,6 +47,7 @@ export type MakeMatchRouteOptions<TRouteTree extends AnyRoute = RegisteredRouter
|
|
|
47
47
|
children?: ((params?: RouteByPath<TRouteTree, ResolveRelativePath<TFrom, NoInfer<TTo>>>['types']['allParams']) => ReactNode) | React.ReactNode;
|
|
48
48
|
};
|
|
49
49
|
export declare function MatchRoute<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = '/', TMaskTo extends string = ''>(props: MakeMatchRouteOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>): any;
|
|
50
|
+
export declare function getRenderedMatches(state: RouterState): RouteMatch<AnyRoute, any>[];
|
|
50
51
|
export declare function useMatch<TRouteTree extends AnyRoute = RegisteredRouter['routeTree'], TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>, TStrict extends boolean = true, TRouteMatchState = RouteMatch<TRouteTree, TFrom>, TSelected = TRouteMatchState>(opts: StrictOrFrom<TFrom> & {
|
|
51
52
|
select?: (match: TRouteMatchState) => TSelected;
|
|
52
53
|
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
@@ -93,13 +93,15 @@
|
|
|
93
93
|
push: (path, state) => {
|
|
94
94
|
state = assignKey(state);
|
|
95
95
|
tryNavigation(() => {
|
|
96
|
-
opts.pushState(path, state
|
|
96
|
+
opts.pushState(path, state);
|
|
97
|
+
onUpdate();
|
|
97
98
|
});
|
|
98
99
|
},
|
|
99
100
|
replace: (path, state) => {
|
|
100
101
|
state = assignKey(state);
|
|
101
102
|
tryNavigation(() => {
|
|
102
|
-
opts.replaceState(path, state
|
|
103
|
+
opts.replaceState(path, state);
|
|
104
|
+
onUpdate();
|
|
103
105
|
});
|
|
104
106
|
},
|
|
105
107
|
go: index => {
|
|
@@ -204,7 +206,7 @@
|
|
|
204
206
|
};
|
|
205
207
|
|
|
206
208
|
// This function queues up a call to update the browser history
|
|
207
|
-
const queueHistoryAction = (type, destHref, state
|
|
209
|
+
const queueHistoryAction = (type, destHref, state) => {
|
|
208
210
|
const href = createHref(destHref);
|
|
209
211
|
if (!scheduled) {
|
|
210
212
|
rollbackLocation = currentLocation;
|
|
@@ -219,9 +221,6 @@
|
|
|
219
221
|
state,
|
|
220
222
|
isPush: next?.isPush || type === 'push'
|
|
221
223
|
};
|
|
222
|
-
|
|
223
|
-
// Notify subscribers
|
|
224
|
-
onUpdate();
|
|
225
224
|
if (!scheduled) {
|
|
226
225
|
// Schedule an update to the browser history
|
|
227
226
|
scheduled = Promise.resolve().then(() => flush());
|
|
@@ -235,8 +234,8 @@
|
|
|
235
234
|
var originalReplaceState = win.history.replaceState;
|
|
236
235
|
const history = createHistory({
|
|
237
236
|
getLocation,
|
|
238
|
-
pushState: (href, state
|
|
239
|
-
replaceState: (href, state
|
|
237
|
+
pushState: (href, state) => queueHistoryAction('push', href, state),
|
|
238
|
+
replaceState: (href, state) => queueHistoryAction('replace', href, state),
|
|
240
239
|
back: () => win.history.back(),
|
|
241
240
|
forward: () => win.history.forward(),
|
|
242
241
|
go: n => win.history.go(n),
|
|
@@ -1462,7 +1461,7 @@
|
|
|
1462
1461
|
function useParams(opts) {
|
|
1463
1462
|
return useRouterState({
|
|
1464
1463
|
select: state => {
|
|
1465
|
-
const params = last(state
|
|
1464
|
+
const params = last(getRenderedMatches(state))?.params;
|
|
1466
1465
|
return opts?.select ? opts.select(params) : params;
|
|
1467
1466
|
}
|
|
1468
1467
|
});
|
|
@@ -3323,6 +3322,7 @@
|
|
|
3323
3322
|
exports.escapeJSON = escapeJSON;
|
|
3324
3323
|
exports.functionalUpdate = functionalUpdate;
|
|
3325
3324
|
exports.getInitialRouterState = getInitialRouterState;
|
|
3325
|
+
exports.getRenderedMatches = getRenderedMatches;
|
|
3326
3326
|
exports.getRouteMatch = getRouteMatch;
|
|
3327
3327
|
exports.interpolatePath = interpolatePath;
|
|
3328
3328
|
exports.invariant = invariant;
|