@remix-run/router 1.0.3-pre.0 → 1.0.3-pre.1
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/CHANGELOG.md +7 -0
- package/dist/history.d.ts +9 -0
- package/dist/router.cjs.js +40 -26
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.js +40 -26
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +40 -26
- package/dist/router.umd.js.map +1 -1
- package/dist/router.umd.min.js +2 -2
- package/dist/router.umd.min.js.map +1 -1
- package/history.ts +36 -0
- package/package.json +1 -1
- package/router.ts +10 -26
- package/utils.ts +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# `@remix-run/router`
|
|
2
2
|
|
|
3
|
+
## 1.0.3-pre.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix `createURL` in local file execution in Firefox ([#9464](https://github.com/remix-run/react-router/pull/9464))
|
|
8
|
+
- make url-encoding history-aware ([#9496](https://github.com/remix-run/react-router/pull/9496))
|
|
9
|
+
|
|
3
10
|
## 1.0.3-pre.0
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/dist/history.d.ts
CHANGED
|
@@ -106,6 +106,14 @@ export interface History {
|
|
|
106
106
|
* @param to - The destination URL
|
|
107
107
|
*/
|
|
108
108
|
createHref(to: To): string;
|
|
109
|
+
/**
|
|
110
|
+
* Encode a location the same way window.history would do (no-op for memory
|
|
111
|
+
* history) so we ensure our PUSH/REPLAC e navigations for data routers
|
|
112
|
+
* behave the same as POP
|
|
113
|
+
*
|
|
114
|
+
* @param location The incoming location from router.navigate()
|
|
115
|
+
*/
|
|
116
|
+
encodeLocation(location: Location): Location;
|
|
109
117
|
/**
|
|
110
118
|
* Pushes a new location onto the history stack, increasing its length by one.
|
|
111
119
|
* If there were any entries in the stack after the current one, they are
|
|
@@ -218,6 +226,7 @@ export declare function createPath({ pathname, search, hash, }: Partial<Path>):
|
|
|
218
226
|
* Parses a string URL path into its separate pathname, search, and hash components.
|
|
219
227
|
*/
|
|
220
228
|
export declare function parsePath(path: string): Partial<Path>;
|
|
229
|
+
export declare function createURL(location: Location | string): URL;
|
|
221
230
|
export interface UrlHistory extends History {
|
|
222
231
|
}
|
|
223
232
|
export declare type UrlHistoryOptions = {
|
package/dist/router.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @remix-run/router v1.0.3-pre.
|
|
2
|
+
* @remix-run/router v1.0.3-pre.1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -113,6 +113,10 @@ function createMemoryHistory(options) {
|
|
|
113
113
|
return typeof to === "string" ? to : createPath(to);
|
|
114
114
|
},
|
|
115
115
|
|
|
116
|
+
encodeLocation(location) {
|
|
117
|
+
return location;
|
|
118
|
+
},
|
|
119
|
+
|
|
116
120
|
push(to, state) {
|
|
117
121
|
action = exports.Action.Push;
|
|
118
122
|
let nextLocation = createMemoryLocation(to, state);
|
|
@@ -370,6 +374,14 @@ function parsePath(path) {
|
|
|
370
374
|
|
|
371
375
|
return parsedPath;
|
|
372
376
|
}
|
|
377
|
+
function createURL(location) {
|
|
378
|
+
// window.location.origin is "null" (the literal string value) in Firefox
|
|
379
|
+
// under certain conditions, notably when serving from a local HTML file
|
|
380
|
+
// See https://bugzilla.mozilla.org/show_bug.cgi?id=878297
|
|
381
|
+
let base = typeof window !== "undefined" && typeof window.location !== "undefined" && window.location.origin !== "null" ? window.location.origin : "unknown://unknown";
|
|
382
|
+
let href = typeof location === "string" ? location : createPath(location);
|
|
383
|
+
return new URL(href, base);
|
|
384
|
+
}
|
|
373
385
|
|
|
374
386
|
function getUrlBasedHistory(getLocation, createHref, validateLocation, options) {
|
|
375
387
|
if (options === void 0) {
|
|
@@ -460,6 +472,16 @@ function getUrlBasedHistory(getLocation, createHref, validateLocation, options)
|
|
|
460
472
|
return createHref(window, to);
|
|
461
473
|
},
|
|
462
474
|
|
|
475
|
+
encodeLocation(location) {
|
|
476
|
+
// Encode a Location the same way window.location would
|
|
477
|
+
let url = createURL(createPath(location));
|
|
478
|
+
return _extends({}, location, {
|
|
479
|
+
pathname: url.pathname,
|
|
480
|
+
search: url.search,
|
|
481
|
+
hash: url.hash
|
|
482
|
+
});
|
|
483
|
+
},
|
|
484
|
+
|
|
463
485
|
push,
|
|
464
486
|
replace,
|
|
465
487
|
|
|
@@ -548,9 +570,12 @@ function matchRoutes(routes, locationArg, basename) {
|
|
|
548
570
|
let matches = null;
|
|
549
571
|
|
|
550
572
|
for (let i = 0; matches == null && i < branches.length; ++i) {
|
|
551
|
-
matches = matchRouteBranch(branches[i], //
|
|
552
|
-
// from
|
|
553
|
-
// in the route definitions
|
|
573
|
+
matches = matchRouteBranch(branches[i], // Incoming pathnames are generally encoded from either window.location
|
|
574
|
+
// or from router.navigate, but we want to match against the unencoded
|
|
575
|
+
// paths in the route definitions. Memory router locations won't be
|
|
576
|
+
// encoded here but there also shouldn't be anything to decode so this
|
|
577
|
+
// should be a safe operation. This avoids needing matchRoutes to be
|
|
578
|
+
// history-aware.
|
|
554
579
|
safelyDecodeURI(pathname));
|
|
555
580
|
}
|
|
556
581
|
|
|
@@ -1482,12 +1507,7 @@ function createRouter(init) {
|
|
|
1482
1507
|
// the same encoding we'd get from a history.pushState/window.location read
|
|
1483
1508
|
// without having to touch history
|
|
1484
1509
|
|
|
1485
|
-
|
|
1486
|
-
location = _extends({}, location, {
|
|
1487
|
-
pathname: url.pathname,
|
|
1488
|
-
search: url.search,
|
|
1489
|
-
hash: url.hash
|
|
1490
|
-
});
|
|
1510
|
+
location = init.history.encodeLocation(location);
|
|
1491
1511
|
let historyAction = (opts && opts.replace) === true || submission != null ? exports.Action.Replace : exports.Action.Push;
|
|
1492
1512
|
let preventScrollReset = opts && "preventScrollReset" in opts ? opts.preventScrollReset === true : undefined;
|
|
1493
1513
|
return await startNavigation(historyAction, location, {
|
|
@@ -2560,8 +2580,6 @@ function unstable_createStaticHandler(routes) {
|
|
|
2560
2580
|
let result;
|
|
2561
2581
|
|
|
2562
2582
|
if (!actionMatch.route.action) {
|
|
2563
|
-
let href = createServerHref(new URL(request.url));
|
|
2564
|
-
|
|
2565
2583
|
if (isRouteRequest) {
|
|
2566
2584
|
throw createRouterErrorResponse(null, {
|
|
2567
2585
|
status: 405,
|
|
@@ -2569,7 +2587,7 @@ function unstable_createStaticHandler(routes) {
|
|
|
2569
2587
|
});
|
|
2570
2588
|
}
|
|
2571
2589
|
|
|
2572
|
-
result = getMethodNotAllowedResult(
|
|
2590
|
+
result = getMethodNotAllowedResult(request.url);
|
|
2573
2591
|
} else {
|
|
2574
2592
|
result = await callLoaderOrAction("action", request, actionMatch, matches, undefined, // Basename not currently supported in static handlers
|
|
2575
2593
|
true, isRouteRequest);
|
|
@@ -2753,7 +2771,7 @@ function normalizeNavigateOptions(to, opts, isFetcher) {
|
|
|
2753
2771
|
path,
|
|
2754
2772
|
submission: {
|
|
2755
2773
|
formMethod: opts.formMethod,
|
|
2756
|
-
formAction:
|
|
2774
|
+
formAction: stripHashFromPath(path),
|
|
2757
2775
|
formEncType: opts && opts.formEncType || "application/x-www-form-urlencoded",
|
|
2758
2776
|
formData: opts.formData
|
|
2759
2777
|
}
|
|
@@ -3033,7 +3051,7 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
|
|
|
3033
3051
|
}
|
|
3034
3052
|
|
|
3035
3053
|
function createRequest(location, signal, submission) {
|
|
3036
|
-
let url = createURL(location).toString();
|
|
3054
|
+
let url = createURL(stripHashFromPath(location)).toString();
|
|
3037
3055
|
let init = {
|
|
3038
3056
|
signal
|
|
3039
3057
|
};
|
|
@@ -3226,7 +3244,7 @@ function getMethodNotAllowedMatches(routes) {
|
|
|
3226
3244
|
}
|
|
3227
3245
|
|
|
3228
3246
|
function getMethodNotAllowedResult(path) {
|
|
3229
|
-
let href = typeof path === "string" ? path :
|
|
3247
|
+
let href = typeof path === "string" ? path : createPath(path);
|
|
3230
3248
|
console.warn("You're trying to submit to a route that does not have an action. To " + "fix this, please add an `action` function to the route for " + ("[" + href + "]"));
|
|
3231
3249
|
return {
|
|
3232
3250
|
type: ResultType.error,
|
|
@@ -3243,11 +3261,13 @@ function findRedirect(results) {
|
|
|
3243
3261
|
return result;
|
|
3244
3262
|
}
|
|
3245
3263
|
}
|
|
3246
|
-
}
|
|
3247
|
-
|
|
3264
|
+
}
|
|
3248
3265
|
|
|
3249
|
-
function
|
|
3250
|
-
|
|
3266
|
+
function stripHashFromPath(path) {
|
|
3267
|
+
let parsedPath = typeof path === "string" ? parsePath(path) : path;
|
|
3268
|
+
return createPath(_extends({}, parsedPath, {
|
|
3269
|
+
hash: ""
|
|
3270
|
+
}));
|
|
3251
3271
|
}
|
|
3252
3272
|
|
|
3253
3273
|
function isHashChangeOnly(a, b) {
|
|
@@ -3365,12 +3385,6 @@ function getTargetMatch(matches, location) {
|
|
|
3365
3385
|
|
|
3366
3386
|
let pathMatches = getPathContributingMatches(matches);
|
|
3367
3387
|
return pathMatches[pathMatches.length - 1];
|
|
3368
|
-
}
|
|
3369
|
-
|
|
3370
|
-
function createURL(location) {
|
|
3371
|
-
let base = typeof window !== "undefined" && typeof window.location !== "undefined" ? window.location.origin : "unknown://unknown";
|
|
3372
|
-
let href = typeof location === "string" ? location : createServerHref(location);
|
|
3373
|
-
return new URL(href, base);
|
|
3374
3388
|
} //#endregion
|
|
3375
3389
|
|
|
3376
3390
|
exports.AbortedDeferredError = AbortedDeferredError;
|