@tanstack/router-core 1.132.0-alpha.12 → 1.132.0-alpha.15
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/index.cjs +5 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +3 -1
- package/dist/cjs/location.d.cts +38 -0
- package/dist/cjs/path.cjs +6 -49
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/path.d.cts +3 -6
- package/dist/cjs/rewrite.cjs +63 -0
- package/dist/cjs/rewrite.cjs.map +1 -0
- package/dist/cjs/rewrite.d.cts +22 -0
- package/dist/cjs/router.cjs +49 -27
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +49 -2
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +6 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/location.d.ts +38 -0
- package/dist/esm/path.d.ts +3 -6
- package/dist/esm/path.js +6 -49
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/rewrite.d.ts +22 -0
- package/dist/esm/rewrite.js +63 -0
- package/dist/esm/rewrite.js.map +1 -0
- package/dist/esm/router.d.ts +49 -2
- package/dist/esm/router.js +51 -29
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +8 -1
- package/src/location.ts +38 -0
- package/src/path.ts +5 -66
- package/src/rewrite.ts +70 -0
- package/src/router.ts +128 -47
package/dist/cjs/router.cjs
CHANGED
|
@@ -12,6 +12,7 @@ const root = require("./root.cjs");
|
|
|
12
12
|
const redirect = require("./redirect.cjs");
|
|
13
13
|
const lruCache = require("./lru-cache.cjs");
|
|
14
14
|
const loadMatches = require("./load-matches.cjs");
|
|
15
|
+
const rewrite = require("./rewrite.cjs");
|
|
15
16
|
function defaultSerializeError(err) {
|
|
16
17
|
if (err instanceof Error) {
|
|
17
18
|
const obj = {
|
|
@@ -56,7 +57,6 @@ class RouterCore {
|
|
|
56
57
|
"The notFoundRoute API is deprecated and will be removed in the next major version. See https://tanstack.com/router/v1/docs/framework/react/guide/not-found-errors#migrating-from-notfoundroute for more info."
|
|
57
58
|
);
|
|
58
59
|
}
|
|
59
|
-
const previousOptions = this.options;
|
|
60
60
|
this.options = {
|
|
61
61
|
...this.options,
|
|
62
62
|
...newOptions
|
|
@@ -68,24 +68,43 @@ class RouterCore {
|
|
|
68
68
|
char
|
|
69
69
|
])
|
|
70
70
|
) : void 0;
|
|
71
|
-
if (!this.
|
|
72
|
-
if (
|
|
73
|
-
this.
|
|
71
|
+
if (!this.history || this.options.history && this.options.history !== this.history) {
|
|
72
|
+
if (!this.options.history) {
|
|
73
|
+
if (!this.isServer) {
|
|
74
|
+
this.history = history.createBrowserHistory();
|
|
75
|
+
}
|
|
74
76
|
} else {
|
|
75
|
-
this.
|
|
77
|
+
this.history = this.options.history;
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
})
|
|
80
|
+
if (this.options.basepath) {
|
|
81
|
+
const basepathRewrite = rewrite.rewriteBasepath({
|
|
82
|
+
basepath: this.options.basepath
|
|
83
|
+
});
|
|
84
|
+
if (this.options.rewrite) {
|
|
85
|
+
this.rewrite = rewrite.composeRewrites([basepathRewrite, this.options.rewrite]);
|
|
86
|
+
} else {
|
|
87
|
+
this.rewrite = basepathRewrite;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
this.rewrite = this.options.rewrite;
|
|
91
|
+
}
|
|
92
|
+
this.origin = this.options.origin;
|
|
93
|
+
if (!this.origin) {
|
|
94
|
+
if (!this.isServer) {
|
|
95
|
+
this.origin = window.origin;
|
|
96
|
+
} else {
|
|
97
|
+
this.origin = "http://localhost";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (this.history) {
|
|
82
101
|
this.updateLatestLocation();
|
|
83
102
|
}
|
|
84
103
|
if (this.options.routeTree !== this.routeTree) {
|
|
85
104
|
this.routeTree = this.options.routeTree;
|
|
86
105
|
this.buildRouteTree();
|
|
87
106
|
}
|
|
88
|
-
if (!this.__store) {
|
|
107
|
+
if (!this.__store && this.latestLocation) {
|
|
89
108
|
this.__store = new store.Store(getInitialRouterState(this.latestLocation), {
|
|
90
109
|
onUpdate: () => {
|
|
91
110
|
this.__store.state = {
|
|
@@ -149,19 +168,24 @@ class RouterCore {
|
|
|
149
168
|
};
|
|
150
169
|
this.parseLocation = (locationToParse, previousLocation) => {
|
|
151
170
|
const parse = ({
|
|
152
|
-
|
|
153
|
-
search,
|
|
154
|
-
hash,
|
|
171
|
+
href,
|
|
155
172
|
state
|
|
156
173
|
}) => {
|
|
157
|
-
const
|
|
174
|
+
const fullUrl = new URL(href, this.origin);
|
|
175
|
+
const url = rewrite.executeRewriteInput(this.rewrite, fullUrl);
|
|
176
|
+
const parsedSearch = this.options.parseSearch(url.search);
|
|
158
177
|
const searchStr = this.options.stringifySearch(parsedSearch);
|
|
178
|
+
url.search = searchStr;
|
|
179
|
+
const fullPath = url.href.replace(url.origin, "");
|
|
180
|
+
const { pathname, hash } = url;
|
|
159
181
|
return {
|
|
182
|
+
href: fullPath,
|
|
183
|
+
publicHref: href,
|
|
184
|
+
url: url.href,
|
|
160
185
|
pathname,
|
|
161
186
|
searchStr,
|
|
162
187
|
search: utils.replaceEqualDeep(previousLocation?.search, parsedSearch),
|
|
163
188
|
hash: hash.split("#").reverse()[0] ?? "",
|
|
164
|
-
href: `${pathname}${searchStr}${hash}`,
|
|
165
189
|
state: utils.replaceEqualDeep(previousLocation?.state, state)
|
|
166
190
|
};
|
|
167
191
|
};
|
|
@@ -181,11 +205,9 @@ class RouterCore {
|
|
|
181
205
|
};
|
|
182
206
|
this.resolvePathWithBase = (from, path$1) => {
|
|
183
207
|
const resolvedPath = path.resolvePath({
|
|
184
|
-
basepath: this.basepath,
|
|
185
208
|
base: from,
|
|
186
209
|
to: path.cleanPath(path$1),
|
|
187
210
|
trailingSlash: this.options.trailingSlash,
|
|
188
|
-
caseSensitive: this.options.caseSensitive,
|
|
189
211
|
parseCache: this.parsePathnameCache
|
|
190
212
|
});
|
|
191
213
|
return resolvedPath;
|
|
@@ -207,7 +229,6 @@ class RouterCore {
|
|
|
207
229
|
return getMatchedRoutes({
|
|
208
230
|
pathname,
|
|
209
231
|
routePathname,
|
|
210
|
-
basepath: this.basepath,
|
|
211
232
|
caseSensitive: this.options.caseSensitive,
|
|
212
233
|
routesByPath: this.routesByPath,
|
|
213
234
|
routesById: this.routesById,
|
|
@@ -315,13 +336,18 @@ class RouterCore {
|
|
|
315
336
|
const hashStr = hash ? `#${hash}` : "";
|
|
316
337
|
let nextState = dest.state === true ? currentLocation.state : dest.state ? utils.functionalUpdate(dest.state, currentLocation.state) : {};
|
|
317
338
|
nextState = utils.replaceEqualDeep(currentLocation.state, nextState);
|
|
339
|
+
const fullPath = `${nextPathname}${searchStr}${hashStr}`;
|
|
340
|
+
const url = new URL(fullPath, this.origin);
|
|
341
|
+
const rewrittenUrl = rewrite.executeRewriteOutput(this.rewrite, url);
|
|
318
342
|
return {
|
|
343
|
+
publicHref: rewrittenUrl.pathname + rewrittenUrl.search + rewrittenUrl.hash,
|
|
344
|
+
href: fullPath,
|
|
345
|
+
url: rewrittenUrl.href,
|
|
319
346
|
pathname: nextPathname,
|
|
320
347
|
search: nextSearch,
|
|
321
348
|
searchStr,
|
|
322
349
|
state: nextState,
|
|
323
350
|
hash: hash ?? "",
|
|
324
|
-
href: `${nextPathname}${searchStr}${hashStr}`,
|
|
325
351
|
unmaskOnReload: dest.unmaskOnReload
|
|
326
352
|
};
|
|
327
353
|
};
|
|
@@ -332,7 +358,6 @@ class RouterCore {
|
|
|
332
358
|
let params = {};
|
|
333
359
|
const foundMask = this.options.routeMasks?.find((d) => {
|
|
334
360
|
const match = path.matchPathname(
|
|
335
|
-
this.basepath,
|
|
336
361
|
next.pathname,
|
|
337
362
|
{
|
|
338
363
|
to: d.from,
|
|
@@ -393,7 +418,7 @@ class RouterCore {
|
|
|
393
418
|
});
|
|
394
419
|
return isEqual;
|
|
395
420
|
};
|
|
396
|
-
const isSameUrl = this.latestLocation.href === next.href;
|
|
421
|
+
const isSameUrl = path.trimPathRight(this.latestLocation.href) === path.trimPathRight(next.href);
|
|
397
422
|
const previousCommitPromise = this.commitLocationPromise;
|
|
398
423
|
this.commitLocationPromise = utils.createControlledPromise(() => {
|
|
399
424
|
previousCommitPromise?.resolve();
|
|
@@ -429,7 +454,7 @@ class RouterCore {
|
|
|
429
454
|
nextHistory.state.__hashScrollIntoViewOptions = hashScrollIntoView ?? this.options.defaultHashScrollIntoView ?? true;
|
|
430
455
|
this.shouldViewTransition = viewTransition;
|
|
431
456
|
this.history[next.replace ? "replace" : "push"](
|
|
432
|
-
nextHistory.
|
|
457
|
+
nextHistory.publicHref,
|
|
433
458
|
nextHistory.state,
|
|
434
459
|
{ ignoreBlocker }
|
|
435
460
|
);
|
|
@@ -482,7 +507,7 @@ class RouterCore {
|
|
|
482
507
|
if (reloadDocument) {
|
|
483
508
|
if (!href) {
|
|
484
509
|
const location = this.buildLocation({ to, ...rest });
|
|
485
|
-
href =
|
|
510
|
+
href = location.href;
|
|
486
511
|
}
|
|
487
512
|
if (rest.replace) {
|
|
488
513
|
window.location.replace(href);
|
|
@@ -829,7 +854,6 @@ class RouterCore {
|
|
|
829
854
|
const pending = opts?.pending === void 0 ? !this.state.isLoading : opts.pending;
|
|
830
855
|
const baseLocation = pending ? this.latestLocation : this.state.resolvedLocation || this.state.location;
|
|
831
856
|
const match = path.matchPathname(
|
|
832
|
-
this.basepath,
|
|
833
857
|
baseLocation.pathname,
|
|
834
858
|
{
|
|
835
859
|
...opts,
|
|
@@ -1007,7 +1031,7 @@ class RouterCore {
|
|
|
1007
1031
|
routeId: route.id,
|
|
1008
1032
|
params: previousMatch ? utils.replaceEqualDeep(previousMatch.params, routeParams) : routeParams,
|
|
1009
1033
|
_strictParams: usedParams,
|
|
1010
|
-
pathname:
|
|
1034
|
+
pathname: interpolatedPath,
|
|
1011
1035
|
updatedAt: Date.now(),
|
|
1012
1036
|
search: previousMatch ? utils.replaceEqualDeep(previousMatch.search, preMatchSearch) : preMatchSearch,
|
|
1013
1037
|
_strictSearch: strictMatchSearch,
|
|
@@ -1259,7 +1283,6 @@ function processRouteTree({
|
|
|
1259
1283
|
function getMatchedRoutes({
|
|
1260
1284
|
pathname,
|
|
1261
1285
|
routePathname,
|
|
1262
|
-
basepath,
|
|
1263
1286
|
caseSensitive,
|
|
1264
1287
|
routesByPath,
|
|
1265
1288
|
routesById,
|
|
@@ -1270,7 +1293,6 @@ function getMatchedRoutes({
|
|
|
1270
1293
|
const trimmedPath = path.trimPathRight(pathname);
|
|
1271
1294
|
const getMatchedParams = (route) => {
|
|
1272
1295
|
const result = path.matchPathname(
|
|
1273
|
-
basepath,
|
|
1274
1296
|
trimmedPath,
|
|
1275
1297
|
{
|
|
1276
1298
|
to: route.fullPath,
|