@tanstack/react-router 0.0.1-beta.204 → 0.0.1-beta.206
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/RouterProvider.js +963 -0
- package/build/cjs/RouterProvider.js.map +1 -0
- package/build/cjs/fileRoute.js +29 -0
- package/build/cjs/fileRoute.js.map +1 -0
- package/build/cjs/index.js +69 -21
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/path.js +211 -0
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/qss.js +65 -0
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/react.js +148 -190
- package/build/cjs/react.js.map +1 -1
- package/build/cjs/redirects.js +27 -0
- package/build/cjs/redirects.js.map +1 -0
- package/build/cjs/route.js +136 -0
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/router.js +203 -0
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/searchParams.js +83 -0
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/utils.js +196 -0
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +1801 -211
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +385 -164
- package/build/types/RouteMatch.d.ts +23 -0
- package/build/types/RouterProvider.d.ts +54 -0
- package/build/types/awaited.d.ts +0 -8
- package/build/types/defer.d.ts +0 -0
- package/build/types/fileRoute.d.ts +17 -0
- package/build/types/history.d.ts +7 -0
- package/build/types/index.d.ts +17 -4
- package/build/types/link.d.ts +98 -0
- package/build/types/location.d.ts +14 -0
- package/build/types/path.d.ts +16 -0
- package/build/types/qss.d.ts +2 -0
- package/build/types/react.d.ts +23 -83
- package/build/types/redirects.d.ts +10 -0
- package/build/types/route.d.ts +222 -0
- package/build/types/routeInfo.d.ts +22 -0
- package/build/types/router.d.ts +115 -0
- package/build/types/scroll-restoration.d.ts +0 -3
- package/build/types/searchParams.d.ts +7 -0
- package/build/types/utils.d.ts +48 -0
- package/build/umd/index.development.js +1118 -1540
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -33
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -4
- package/src/RouteMatch.ts +28 -0
- package/src/RouterProvider.tsx +1390 -0
- package/src/awaited.tsx +40 -40
- package/src/defer.ts +55 -0
- package/src/fileRoute.ts +143 -0
- package/src/history.ts +8 -0
- package/src/index.tsx +18 -5
- package/src/link.ts +347 -0
- package/src/location.ts +14 -0
- package/src/path.ts +256 -0
- package/src/qss.ts +53 -0
- package/src/react.tsx +174 -422
- package/src/redirects.ts +31 -0
- package/src/route.ts +710 -0
- package/src/routeInfo.ts +68 -0
- package/src/router.ts +373 -0
- package/src/scroll-restoration.tsx +205 -27
- package/src/searchParams.ts +78 -0
- package/src/utils.ts +257 -0
- package/build/cjs/awaited.js +0 -45
- package/build/cjs/awaited.js.map +0 -1
- package/build/cjs/scroll-restoration.js +0 -56
- package/build/cjs/scroll-restoration.js.map +0 -1
package/build/cjs/qss.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tanstack/react-router/src/index.tsx
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) TanStack
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
+
|
|
15
|
+
// @ts-nocheck
|
|
16
|
+
|
|
17
|
+
// qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.
|
|
18
|
+
|
|
19
|
+
function encode(obj, pfx) {
|
|
20
|
+
var k,
|
|
21
|
+
i,
|
|
22
|
+
tmp,
|
|
23
|
+
str = '';
|
|
24
|
+
for (k in obj) {
|
|
25
|
+
if ((tmp = obj[k]) !== void 0) {
|
|
26
|
+
if (Array.isArray(tmp)) {
|
|
27
|
+
for (i = 0; i < tmp.length; i++) {
|
|
28
|
+
str && (str += '&');
|
|
29
|
+
str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i]);
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
str && (str += '&');
|
|
33
|
+
str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return (pfx || '') + str;
|
|
38
|
+
}
|
|
39
|
+
function toValue(mix) {
|
|
40
|
+
if (!mix) return '';
|
|
41
|
+
var str = decodeURIComponent(mix);
|
|
42
|
+
if (str === 'false') return false;
|
|
43
|
+
if (str === 'true') return true;
|
|
44
|
+
return +str * 0 === 0 && +str + '' === str ? +str : str;
|
|
45
|
+
}
|
|
46
|
+
function decode(str) {
|
|
47
|
+
var tmp,
|
|
48
|
+
k,
|
|
49
|
+
out = {},
|
|
50
|
+
arr = str.split('&');
|
|
51
|
+
while (tmp = arr.shift()) {
|
|
52
|
+
tmp = tmp.split('=');
|
|
53
|
+
k = tmp.shift();
|
|
54
|
+
if (out[k] !== void 0) {
|
|
55
|
+
out[k] = [].concat(out[k], toValue(tmp.shift()));
|
|
56
|
+
} else {
|
|
57
|
+
out[k] = toValue(tmp.shift());
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.decode = decode;
|
|
64
|
+
exports.encode = encode;
|
|
65
|
+
//# sourceMappingURL=qss.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qss.js","sources":["../../src/qss.ts"],"sourcesContent":["// @ts-nocheck\n\n// qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.\n\nexport function encode(obj, pfx?: string) {\n var k,\n i,\n tmp,\n str = ''\n\n for (k in obj) {\n if ((tmp = obj[k]) !== void 0) {\n if (Array.isArray(tmp)) {\n for (i = 0; i < tmp.length; i++) {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i])\n }\n } else {\n str && (str += '&')\n str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp)\n }\n }\n }\n\n return (pfx || '') + str\n}\n\nfunction toValue(mix) {\n if (!mix) return ''\n var str = decodeURIComponent(mix)\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 && +str + '' === str ? +str : str\n}\n\nexport function decode(str) {\n var tmp,\n k,\n out = {},\n arr = str.split('&')\n\n while ((tmp = arr.shift())) {\n tmp = tmp.split('=')\n k = tmp.shift()\n if (out[k] !== void 0) {\n out[k] = [].concat(out[k], toValue(tmp.shift()))\n } else {\n out[k] = toValue(tmp.shift())\n }\n }\n\n return out\n}\n"],"names":["encode","obj","pfx","k","i","tmp","str","Array","isArray","length","encodeURIComponent","toValue","mix","decodeURIComponent","decode","out","arr","split","shift","concat"],"mappings":";;;;;;;;;;;;;;AAAA;;AAEA;;AAEO,SAASA,MAAMA,CAACC,GAAG,EAAEC,GAAY,EAAE;AACxC,EAAA,IAAIC,CAAC;IACHC,CAAC;IACDC,GAAG;AACHC,IAAAA,GAAG,GAAG,EAAE,CAAA;EAEV,KAAKH,CAAC,IAAIF,GAAG,EAAE;IACb,IAAI,CAACI,GAAG,GAAGJ,GAAG,CAACE,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;AAC7B,MAAA,IAAII,KAAK,CAACC,OAAO,CAACH,GAAG,CAAC,EAAE;AACtB,QAAA,KAAKD,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGC,GAAG,CAACI,MAAM,EAAEL,CAAC,EAAE,EAAE;AAC/BE,UAAAA,GAAG,KAAKA,GAAG,IAAI,GAAG,CAAC,CAAA;AACnBA,UAAAA,GAAG,IAAII,kBAAkB,CAACP,CAAC,CAAC,GAAG,GAAG,GAAGO,kBAAkB,CAACL,GAAG,CAACD,CAAC,CAAC,CAAC,CAAA;AACjE,SAAA;AACF,OAAC,MAAM;AACLE,QAAAA,GAAG,KAAKA,GAAG,IAAI,GAAG,CAAC,CAAA;QACnBA,GAAG,IAAII,kBAAkB,CAACP,CAAC,CAAC,GAAG,GAAG,GAAGO,kBAAkB,CAACL,GAAG,CAAC,CAAA;AAC9D,OAAA;AACF,KAAA;AACF,GAAA;AAEA,EAAA,OAAO,CAACH,GAAG,IAAI,EAAE,IAAII,GAAG,CAAA;AAC1B,CAAA;AAEA,SAASK,OAAOA,CAACC,GAAG,EAAE;AACpB,EAAA,IAAI,CAACA,GAAG,EAAE,OAAO,EAAE,CAAA;AACnB,EAAA,IAAIN,GAAG,GAAGO,kBAAkB,CAACD,GAAG,CAAC,CAAA;AACjC,EAAA,IAAIN,GAAG,KAAK,OAAO,EAAE,OAAO,KAAK,CAAA;AACjC,EAAA,IAAIA,GAAG,KAAK,MAAM,EAAE,OAAO,IAAI,CAAA;AAC/B,EAAA,OAAO,CAACA,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAACA,GAAG,GAAG,EAAE,KAAKA,GAAG,GAAG,CAACA,GAAG,GAAGA,GAAG,CAAA;AACzD,CAAA;AAEO,SAASQ,MAAMA,CAACR,GAAG,EAAE;AAC1B,EAAA,IAAID,GAAG;IACLF,CAAC;IACDY,GAAG,GAAG,EAAE;AACRC,IAAAA,GAAG,GAAGV,GAAG,CAACW,KAAK,CAAC,GAAG,CAAC,CAAA;AAEtB,EAAA,OAAQZ,GAAG,GAAGW,GAAG,CAACE,KAAK,EAAE,EAAG;AAC1Bb,IAAAA,GAAG,GAAGA,GAAG,CAACY,KAAK,CAAC,GAAG,CAAC,CAAA;AACpBd,IAAAA,CAAC,GAAGE,GAAG,CAACa,KAAK,EAAE,CAAA;AACf,IAAA,IAAIH,GAAG,CAACZ,CAAC,CAAC,KAAK,KAAK,CAAC,EAAE;MACrBY,GAAG,CAACZ,CAAC,CAAC,GAAG,EAAE,CAACgB,MAAM,CAACJ,GAAG,CAACZ,CAAC,CAAC,EAAEQ,OAAO,CAACN,GAAG,CAACa,KAAK,EAAE,CAAC,CAAC,CAAA;AAClD,KAAC,MAAM;MACLH,GAAG,CAACZ,CAAC,CAAC,GAAGQ,OAAO,CAACN,GAAG,CAACa,KAAK,EAAE,CAAC,CAAA;AAC/B,KAAA;AACF,GAAA;AAEA,EAAA,OAAOH,GAAG,CAAA;AACZ;;;;;"}
|
package/build/cjs/react.js
CHANGED
|
@@ -14,10 +14,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
14
14
|
|
|
15
15
|
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
|
|
16
16
|
var React = require('react');
|
|
17
|
-
var reactStore = require('@tanstack/react-store');
|
|
18
17
|
var invariant = require('tiny-invariant');
|
|
19
18
|
var warning = require('tiny-warning');
|
|
20
|
-
var
|
|
19
|
+
var route = require('./route.js');
|
|
20
|
+
var utils = require('./utils.js');
|
|
21
|
+
var RouterProvider = require('./RouterProvider.js');
|
|
21
22
|
|
|
22
23
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
23
24
|
|
|
@@ -44,41 +45,6 @@ var invariant__default = /*#__PURE__*/_interopDefaultLegacy(invariant);
|
|
|
44
45
|
var warning__default = /*#__PURE__*/_interopDefaultLegacy(warning);
|
|
45
46
|
|
|
46
47
|
const useLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
47
|
-
routerCore.Route.__onInit = route => {
|
|
48
|
-
Object.assign(route, {
|
|
49
|
-
useMatch: (opts = {}) => {
|
|
50
|
-
return useMatch({
|
|
51
|
-
...opts,
|
|
52
|
-
from: route.id
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
useLoader: (opts = {}) => {
|
|
56
|
-
return useLoader({
|
|
57
|
-
...opts,
|
|
58
|
-
from: route.id
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
useRouteContext: (opts = {}) => {
|
|
62
|
-
return useMatch({
|
|
63
|
-
...opts,
|
|
64
|
-
from: route.id,
|
|
65
|
-
select: d => opts?.select ? opts.select(d.context) : d.context
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
useSearch: (opts = {}) => {
|
|
69
|
-
return useSearch({
|
|
70
|
-
...opts,
|
|
71
|
-
from: route.id
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
useParams: (opts = {}) => {
|
|
75
|
-
return useParams({
|
|
76
|
-
...opts,
|
|
77
|
-
from: route.id
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
48
|
|
|
83
49
|
//
|
|
84
50
|
|
|
@@ -103,7 +69,10 @@ function lazyRouteComponent(importer, exportName) {
|
|
|
103
69
|
//
|
|
104
70
|
|
|
105
71
|
function useLinkProps(options) {
|
|
106
|
-
const
|
|
72
|
+
const {
|
|
73
|
+
buildLink,
|
|
74
|
+
state: routerState
|
|
75
|
+
} = useRouter();
|
|
107
76
|
const match = useMatch({
|
|
108
77
|
strict: false
|
|
109
78
|
});
|
|
@@ -137,7 +106,7 @@ function useLinkProps(options) {
|
|
|
137
106
|
onTouchStart,
|
|
138
107
|
...rest
|
|
139
108
|
} = options;
|
|
140
|
-
const linkInfo =
|
|
109
|
+
const linkInfo = buildLink(routerState, {
|
|
141
110
|
from: options.to ? match.pathname : undefined,
|
|
142
111
|
...options
|
|
143
112
|
});
|
|
@@ -174,10 +143,10 @@ function useLinkProps(options) {
|
|
|
174
143
|
};
|
|
175
144
|
|
|
176
145
|
// Get the active props
|
|
177
|
-
const resolvedActiveProps = isActive ?
|
|
146
|
+
const resolvedActiveProps = isActive ? utils.functionalUpdate(activeProps, {}) ?? {} : {};
|
|
178
147
|
|
|
179
148
|
// Get the inactive props
|
|
180
|
-
const resolvedInactiveProps = isActive ? {} :
|
|
149
|
+
const resolvedInactiveProps = isActive ? {} : utils.functionalUpdate(inactiveProps, {}) ?? {};
|
|
181
150
|
return {
|
|
182
151
|
...resolvedActiveProps,
|
|
183
152
|
...resolvedInactiveProps,
|
|
@@ -213,92 +182,48 @@ const Link = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
|
|
|
213
182
|
}));
|
|
214
183
|
});
|
|
215
184
|
function Navigate(props) {
|
|
216
|
-
const
|
|
185
|
+
const {
|
|
186
|
+
navigate
|
|
187
|
+
} = useRouter();
|
|
217
188
|
const match = useMatch({
|
|
218
189
|
strict: false
|
|
219
190
|
});
|
|
220
191
|
useLayoutEffect(() => {
|
|
221
|
-
|
|
192
|
+
navigate({
|
|
222
193
|
from: props.to ? match.pathname : undefined,
|
|
223
194
|
...props
|
|
224
195
|
});
|
|
225
196
|
}, []);
|
|
226
197
|
return null;
|
|
227
198
|
}
|
|
228
|
-
const
|
|
229
|
-
const routerContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
230
|
-
function useRouterState(opts) {
|
|
231
|
-
const router = useRouter();
|
|
232
|
-
return reactStore.useStore(router.__store, opts?.select);
|
|
233
|
-
}
|
|
234
|
-
function RouterProvider({
|
|
235
|
-
router,
|
|
236
|
-
...rest
|
|
237
|
-
}) {
|
|
238
|
-
router.update(rest);
|
|
239
|
-
React__namespace.useEffect(() => {
|
|
240
|
-
let unsub;
|
|
241
|
-
React__namespace.startTransition(() => {
|
|
242
|
-
unsub = router.mount();
|
|
243
|
-
});
|
|
244
|
-
return unsub;
|
|
245
|
-
}, [router]);
|
|
246
|
-
const Wrap = router.options.Wrap || React__namespace.Fragment;
|
|
247
|
-
return /*#__PURE__*/React__namespace.createElement(Wrap, null, /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
|
|
248
|
-
value: router
|
|
249
|
-
}, /*#__PURE__*/React__namespace.createElement(Matches, null)));
|
|
250
|
-
}
|
|
251
|
-
function Matches() {
|
|
252
|
-
const router = useRouter();
|
|
253
|
-
const matchIds = useRouterState({
|
|
254
|
-
select: state => {
|
|
255
|
-
return state.renderedMatchIds;
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
const locationKey = useRouterState({
|
|
259
|
-
select: d => d.resolvedLocation.state?.key
|
|
260
|
-
});
|
|
261
|
-
const route = router.getRoute(routerCore.rootRouteId);
|
|
262
|
-
const errorComponent = React__namespace.useCallback(props => {
|
|
263
|
-
return /*#__PURE__*/React__namespace.createElement(ErrorComponent, {
|
|
264
|
-
...props,
|
|
265
|
-
useMatch: route.useMatch,
|
|
266
|
-
useRouteContext: route.useRouteContext,
|
|
267
|
-
useSearch: route.useSearch,
|
|
268
|
-
useParams: route.useParams
|
|
269
|
-
});
|
|
270
|
-
}, [route]);
|
|
271
|
-
return /*#__PURE__*/React__namespace.createElement(matchIdsContext.Provider, {
|
|
272
|
-
value: [undefined, ...matchIds]
|
|
273
|
-
}, /*#__PURE__*/React__namespace.createElement(CatchBoundary, {
|
|
274
|
-
resetKey: locationKey,
|
|
275
|
-
errorComponent: errorComponent,
|
|
276
|
-
onCatch: () => {
|
|
277
|
-
warning__default["default"](false, `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`);
|
|
278
|
-
}
|
|
279
|
-
}, /*#__PURE__*/React__namespace.createElement(Outlet, null)));
|
|
280
|
-
}
|
|
199
|
+
const matchesContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
281
200
|
function useRouter() {
|
|
282
|
-
const value = React__namespace.useContext(routerContext);
|
|
283
|
-
warning__default["default"](value, 'useRouter must be used inside a <
|
|
201
|
+
const value = React__namespace.useContext(RouterProvider.routerContext);
|
|
202
|
+
warning__default["default"](value, 'useRouter must be used inside a <RouterProvider> component!');
|
|
284
203
|
return value;
|
|
285
204
|
}
|
|
205
|
+
function useRouterState(opts) {
|
|
206
|
+
const {
|
|
207
|
+
state
|
|
208
|
+
} = useRouter();
|
|
209
|
+
// return useStore(router.__store, opts?.select as any)
|
|
210
|
+
return opts?.select ? opts.select(state) : state;
|
|
211
|
+
}
|
|
286
212
|
function useMatches(opts) {
|
|
287
|
-
const
|
|
213
|
+
const contextMatches = React__namespace.useContext(matchesContext);
|
|
288
214
|
return useRouterState({
|
|
289
215
|
select: state => {
|
|
290
|
-
const matches = state.
|
|
216
|
+
const matches = state.matches.slice(state.matches.findIndex(d => d.id === contextMatches[0]?.id));
|
|
291
217
|
return opts?.select ? opts.select(matches) : matches;
|
|
292
218
|
}
|
|
293
219
|
});
|
|
294
220
|
}
|
|
295
221
|
function useMatch(opts) {
|
|
296
|
-
const
|
|
297
|
-
const
|
|
298
|
-
const nearestMatchRouteId = router.getRouteMatch(nearestMatchId)?.routeId;
|
|
222
|
+
const nearestMatch = React__namespace.useContext(matchesContext)[0];
|
|
223
|
+
const nearestMatchRouteId = nearestMatch?.routeId;
|
|
299
224
|
const matchRouteId = useRouterState({
|
|
300
225
|
select: state => {
|
|
301
|
-
const match = opts?.from ? state.
|
|
226
|
+
const match = opts?.from ? state.matches.find(d => d.routeId === opts?.from) : state.matches.find(d => d.id === nearestMatch.id);
|
|
302
227
|
return match.routeId;
|
|
303
228
|
}
|
|
304
229
|
});
|
|
@@ -307,29 +232,17 @@ function useMatch(opts) {
|
|
|
307
232
|
}
|
|
308
233
|
const matchSelection = useRouterState({
|
|
309
234
|
select: state => {
|
|
310
|
-
const match = opts?.from ? state.
|
|
235
|
+
const match = opts?.from ? state.matches.find(d => d.routeId === opts?.from) : state.matches.find(d => d.id === nearestMatch.id);
|
|
311
236
|
invariant__default["default"](match, `Could not find ${opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
|
|
312
237
|
return opts?.select ? opts.select(match) : match;
|
|
313
238
|
}
|
|
314
239
|
});
|
|
315
240
|
return matchSelection;
|
|
316
241
|
}
|
|
317
|
-
function
|
|
318
|
-
return useMatch({
|
|
319
|
-
...opts,
|
|
320
|
-
select: match => opts?.select ? opts?.select(match.loaderData) : match.loaderData
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
function useRouterContext(opts) {
|
|
242
|
+
function useRouteMeta(opts) {
|
|
324
243
|
return useMatch({
|
|
325
244
|
...opts,
|
|
326
|
-
select: match => opts?.select ? opts.select(match.
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
function useRouteContext(opts) {
|
|
330
|
-
return useMatch({
|
|
331
|
-
...opts,
|
|
332
|
-
select: match => opts?.select ? opts.select(match.context) : match.context
|
|
245
|
+
select: match => opts?.select ? opts.select(match.meta) : match.meta
|
|
333
246
|
});
|
|
334
247
|
}
|
|
335
248
|
function useSearch(opts) {
|
|
@@ -343,18 +256,20 @@ function useSearch(opts) {
|
|
|
343
256
|
function useParams(opts) {
|
|
344
257
|
return useRouterState({
|
|
345
258
|
select: state => {
|
|
346
|
-
const params =
|
|
259
|
+
const params = utils.last(state.matches)?.params;
|
|
347
260
|
return opts?.select ? opts.select(params) : params;
|
|
348
261
|
}
|
|
349
262
|
});
|
|
350
263
|
}
|
|
351
264
|
function useNavigate(defaultOpts) {
|
|
352
|
-
const
|
|
265
|
+
const {
|
|
266
|
+
navigate
|
|
267
|
+
} = useRouter();
|
|
353
268
|
const match = useMatch({
|
|
354
269
|
strict: false
|
|
355
270
|
});
|
|
356
271
|
return React__namespace.useCallback(opts => {
|
|
357
|
-
return
|
|
272
|
+
return navigate({
|
|
358
273
|
from: opts?.to ? match.pathname : undefined,
|
|
359
274
|
...defaultOpts,
|
|
360
275
|
...opts
|
|
@@ -362,19 +277,62 @@ function useNavigate(defaultOpts) {
|
|
|
362
277
|
}, []);
|
|
363
278
|
}
|
|
364
279
|
function useMatchRoute() {
|
|
365
|
-
const
|
|
280
|
+
const {
|
|
281
|
+
state,
|
|
282
|
+
matchRoute
|
|
283
|
+
} = useRouter();
|
|
366
284
|
return React__namespace.useCallback(opts => {
|
|
367
285
|
const {
|
|
368
286
|
pending,
|
|
369
287
|
caseSensitive,
|
|
370
288
|
...rest
|
|
371
289
|
} = opts;
|
|
372
|
-
return
|
|
290
|
+
return matchRoute(state, rest, {
|
|
373
291
|
pending,
|
|
374
292
|
caseSensitive
|
|
375
293
|
});
|
|
376
294
|
}, []);
|
|
377
295
|
}
|
|
296
|
+
function Matches() {
|
|
297
|
+
const {
|
|
298
|
+
routesById,
|
|
299
|
+
state
|
|
300
|
+
} = useRouter();
|
|
301
|
+
|
|
302
|
+
// const matches = useRouterState({
|
|
303
|
+
// select: (state) => {
|
|
304
|
+
// return state.matches
|
|
305
|
+
// },
|
|
306
|
+
// })
|
|
307
|
+
|
|
308
|
+
const {
|
|
309
|
+
matches
|
|
310
|
+
} = state;
|
|
311
|
+
const locationKey = useRouterState({
|
|
312
|
+
select: d => d.resolvedLocation.state?.key
|
|
313
|
+
});
|
|
314
|
+
const route$1 = routesById[route.rootRouteId];
|
|
315
|
+
const errorComponent = React__namespace.useCallback(props => {
|
|
316
|
+
return /*#__PURE__*/React__namespace.createElement(ErrorComponent, {
|
|
317
|
+
...props,
|
|
318
|
+
useMatch: route$1.useMatch,
|
|
319
|
+
useRouteMeta: route$1.useRouteMeta,
|
|
320
|
+
useSearch: route$1.useSearch,
|
|
321
|
+
useParams: route$1.useParams
|
|
322
|
+
});
|
|
323
|
+
}, [route$1]);
|
|
324
|
+
return /*#__PURE__*/React__namespace.createElement(matchesContext.Provider, {
|
|
325
|
+
value: matches
|
|
326
|
+
}, /*#__PURE__*/React__namespace.createElement(CatchBoundary, {
|
|
327
|
+
resetKey: locationKey,
|
|
328
|
+
errorComponent: errorComponent,
|
|
329
|
+
onCatch: () => {
|
|
330
|
+
warning__default["default"](false, `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`);
|
|
331
|
+
}
|
|
332
|
+
}, matches.length ? /*#__PURE__*/React__namespace.createElement(Match, {
|
|
333
|
+
matches: matches
|
|
334
|
+
}) : null));
|
|
335
|
+
}
|
|
378
336
|
function MatchRoute(props) {
|
|
379
337
|
const matchRoute = useMatchRoute();
|
|
380
338
|
const params = matchRoute(props);
|
|
@@ -384,44 +342,47 @@ function MatchRoute(props) {
|
|
|
384
342
|
return !!params ? props.children : null;
|
|
385
343
|
}
|
|
386
344
|
function Outlet() {
|
|
387
|
-
const
|
|
388
|
-
if (!
|
|
345
|
+
const matches = React__namespace.useContext(matchesContext).slice(1);
|
|
346
|
+
if (!matches[0]) {
|
|
389
347
|
return null;
|
|
390
348
|
}
|
|
391
349
|
return /*#__PURE__*/React__namespace.createElement(Match, {
|
|
392
|
-
|
|
350
|
+
matches: matches
|
|
393
351
|
});
|
|
394
352
|
}
|
|
395
353
|
const defaultPending = () => null;
|
|
396
354
|
function Match({
|
|
397
|
-
|
|
355
|
+
matches
|
|
398
356
|
}) {
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
357
|
+
const {
|
|
358
|
+
options,
|
|
359
|
+
routesById
|
|
360
|
+
} = useRouter();
|
|
361
|
+
const match = matches[0];
|
|
362
|
+
const routeId = match?.routeId;
|
|
363
|
+
const route = routesById[routeId];
|
|
403
364
|
const locationKey = useRouterState({
|
|
404
365
|
select: s => s.resolvedLocation.state?.key
|
|
405
366
|
});
|
|
406
|
-
const PendingComponent = route.options.pendingComponent ??
|
|
407
|
-
const routeErrorComponent = route.options.errorComponent ??
|
|
367
|
+
const PendingComponent = route.options.pendingComponent ?? options.defaultPendingComponent ?? defaultPending;
|
|
368
|
+
const routeErrorComponent = route.options.errorComponent ?? options.defaultErrorComponent ?? ErrorComponent;
|
|
408
369
|
const ResolvedSuspenseBoundary = route.options.wrapInSuspense ?? !route.isRoot ? React__namespace.Suspense : SafeFragment;
|
|
409
370
|
const ResolvedCatchBoundary = !!routeErrorComponent ? CatchBoundary : SafeFragment;
|
|
410
371
|
const errorComponent = React__namespace.useCallback(props => {
|
|
411
372
|
return /*#__PURE__*/React__namespace.createElement(routeErrorComponent, {
|
|
412
373
|
...props,
|
|
413
374
|
useMatch: route.useMatch,
|
|
414
|
-
|
|
375
|
+
useRouteMeta: route.useRouteMeta,
|
|
415
376
|
useSearch: route.useSearch,
|
|
416
377
|
useParams: route.useParams
|
|
417
378
|
});
|
|
418
379
|
}, [route]);
|
|
419
|
-
return /*#__PURE__*/React__namespace.createElement(
|
|
420
|
-
value:
|
|
380
|
+
return /*#__PURE__*/React__namespace.createElement(matchesContext.Provider, {
|
|
381
|
+
value: matches
|
|
421
382
|
}, /*#__PURE__*/React__namespace.createElement(ResolvedSuspenseBoundary, {
|
|
422
383
|
fallback: /*#__PURE__*/React__namespace.createElement(PendingComponent, {
|
|
423
384
|
useMatch: route.useMatch,
|
|
424
|
-
|
|
385
|
+
useRouteMeta: route.useRouteMeta,
|
|
425
386
|
useSearch: route.useSearch,
|
|
426
387
|
useParams: route.useParams
|
|
427
388
|
})
|
|
@@ -429,44 +390,32 @@ function Match({
|
|
|
429
390
|
resetKey: locationKey,
|
|
430
391
|
errorComponent: errorComponent,
|
|
431
392
|
onCatch: () => {
|
|
432
|
-
warning__default["default"](false, `Error in route match: ${
|
|
393
|
+
warning__default["default"](false, `Error in route match: ${match.id}`);
|
|
433
394
|
}
|
|
434
395
|
}, /*#__PURE__*/React__namespace.createElement(MatchInner, {
|
|
435
|
-
|
|
436
|
-
PendingComponent: PendingComponent
|
|
396
|
+
match: match
|
|
437
397
|
}))));
|
|
438
398
|
}
|
|
439
399
|
function MatchInner({
|
|
440
|
-
|
|
441
|
-
PendingComponent
|
|
400
|
+
match
|
|
442
401
|
}) {
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
const route = router.getRoute(match.routeId);
|
|
402
|
+
const {
|
|
403
|
+
options,
|
|
404
|
+
routesById
|
|
405
|
+
} = useRouter();
|
|
406
|
+
const route = routesById[match.routeId];
|
|
451
407
|
if (match.status === 'error') {
|
|
452
408
|
throw match.error;
|
|
453
409
|
}
|
|
454
410
|
if (match.status === 'pending') {
|
|
455
|
-
|
|
456
|
-
useLoader: route.useLoader,
|
|
457
|
-
useMatch: route.useMatch,
|
|
458
|
-
useRouteContext: route.useRouteContext,
|
|
459
|
-
useSearch: route.useSearch,
|
|
460
|
-
useParams: route.useParams
|
|
461
|
-
});
|
|
411
|
+
throw match.loadPromise;
|
|
462
412
|
}
|
|
463
413
|
if (match.status === 'success') {
|
|
464
|
-
let comp = route.options.component ??
|
|
414
|
+
let comp = route.options.component ?? options.defaultComponent;
|
|
465
415
|
if (comp) {
|
|
466
416
|
return /*#__PURE__*/React__namespace.createElement(comp, {
|
|
467
|
-
useLoader: route.useLoader,
|
|
468
417
|
useMatch: route.useMatch,
|
|
469
|
-
|
|
418
|
+
useRouteMeta: route.useRouteMeta,
|
|
470
419
|
useSearch: route.useSearch,
|
|
471
420
|
useParams: route.useParams
|
|
472
421
|
});
|
|
@@ -478,24 +427,37 @@ function MatchInner({
|
|
|
478
427
|
function SafeFragment(props) {
|
|
479
428
|
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, props.children);
|
|
480
429
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
function
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
430
|
+
|
|
431
|
+
// export function useInjectHtml() {
|
|
432
|
+
// const { } = useRouter()
|
|
433
|
+
|
|
434
|
+
// return React.useCallback(
|
|
435
|
+
// (html: string | (() => Promise<string> | string)) => {
|
|
436
|
+
// router.injectHtml(html)
|
|
437
|
+
// },
|
|
438
|
+
// [],
|
|
439
|
+
// )
|
|
440
|
+
// }
|
|
441
|
+
|
|
442
|
+
// export function useDehydrate() {
|
|
443
|
+
// const { } = useRouter()
|
|
444
|
+
|
|
445
|
+
// return React.useCallback(function dehydrate<T>(
|
|
446
|
+
// key: any,
|
|
447
|
+
// data: T | (() => Promise<T> | T),
|
|
448
|
+
// ) {
|
|
449
|
+
// return router.dehydrateData(key, data)
|
|
450
|
+
// },
|
|
451
|
+
// [])
|
|
452
|
+
// }
|
|
453
|
+
|
|
454
|
+
// export function useHydrate() {
|
|
455
|
+
// const { } = useRouter()
|
|
456
|
+
|
|
457
|
+
// return function hydrate<T = unknown>(key: any) {
|
|
458
|
+
// return router.hydrateData(key) as T
|
|
459
|
+
// }
|
|
460
|
+
// }
|
|
499
461
|
|
|
500
462
|
// This is the messiest thing ever... I'm either seriously tired (likely) or
|
|
501
463
|
// there has to be a better way to reset error boundaries when the
|
|
@@ -586,10 +548,12 @@ function ErrorComponent({
|
|
|
586
548
|
}, error.message ? /*#__PURE__*/React__namespace.createElement("code", null, error.message) : null)) : null);
|
|
587
549
|
}
|
|
588
550
|
function useBlocker(message, condition = true) {
|
|
589
|
-
const
|
|
551
|
+
const {
|
|
552
|
+
history
|
|
553
|
+
} = useRouter();
|
|
590
554
|
React__namespace.useEffect(() => {
|
|
591
555
|
if (!condition) return;
|
|
592
|
-
let unblock =
|
|
556
|
+
let unblock = history.block((retry, cancel) => {
|
|
593
557
|
if (window.confirm(message)) {
|
|
594
558
|
unblock();
|
|
595
559
|
retry();
|
|
@@ -631,27 +595,21 @@ exports.CatchBoundaryImpl = CatchBoundaryImpl;
|
|
|
631
595
|
exports.ErrorComponent = ErrorComponent;
|
|
632
596
|
exports.Link = Link;
|
|
633
597
|
exports.MatchRoute = MatchRoute;
|
|
598
|
+
exports.Matches = Matches;
|
|
634
599
|
exports.Navigate = Navigate;
|
|
635
600
|
exports.Outlet = Outlet;
|
|
636
|
-
exports.RouterProvider = RouterProvider;
|
|
637
601
|
exports.lazyRouteComponent = lazyRouteComponent;
|
|
638
|
-
exports.
|
|
639
|
-
exports.routerContext = routerContext;
|
|
602
|
+
exports.matchesContext = matchesContext;
|
|
640
603
|
exports.shallow = shallow;
|
|
641
604
|
exports.useBlocker = useBlocker;
|
|
642
|
-
exports.useDehydrate = useDehydrate;
|
|
643
|
-
exports.useHydrate = useHydrate;
|
|
644
|
-
exports.useInjectHtml = useInjectHtml;
|
|
645
605
|
exports.useLinkProps = useLinkProps;
|
|
646
|
-
exports.useLoader = useLoader;
|
|
647
606
|
exports.useMatch = useMatch;
|
|
648
607
|
exports.useMatchRoute = useMatchRoute;
|
|
649
608
|
exports.useMatches = useMatches;
|
|
650
609
|
exports.useNavigate = useNavigate;
|
|
651
610
|
exports.useParams = useParams;
|
|
652
|
-
exports.
|
|
611
|
+
exports.useRouteMeta = useRouteMeta;
|
|
653
612
|
exports.useRouter = useRouter;
|
|
654
|
-
exports.useRouterContext = useRouterContext;
|
|
655
613
|
exports.useRouterState = useRouterState;
|
|
656
614
|
exports.useSearch = useSearch;
|
|
657
615
|
//# sourceMappingURL=react.js.map
|