@remix-run/router 1.0.5-pre.0 → 1.0.5-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/router.cjs.js +30 -25
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.js +30 -25
- package/dist/router.js.map +1 -1
- package/dist/router.umd.js +30 -25
- 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/dist/utils.d.ts +0 -1
- package/package.json +1 -1
- package/router.ts +30 -24
- package/utils.ts +0 -1
package/dist/utils.d.ts
CHANGED
package/package.json
CHANGED
package/router.ts
CHANGED
|
@@ -1606,17 +1606,17 @@ export function createRouter(init: RouterInit): Router {
|
|
|
1606
1606
|
"Expected a location on the redirect navigation"
|
|
1607
1607
|
);
|
|
1608
1608
|
|
|
1609
|
-
if
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1609
|
+
// Check if this an external redirect that goes to a new origin
|
|
1610
|
+
if (typeof window?.location !== "undefined") {
|
|
1611
|
+
let newOrigin = createClientSideURL(redirect.location).origin;
|
|
1612
|
+
if (window.location.origin !== newOrigin) {
|
|
1613
|
+
if (replace) {
|
|
1614
|
+
window.location.replace(redirect.location);
|
|
1615
|
+
} else {
|
|
1616
|
+
window.location.assign(redirect.location);
|
|
1617
|
+
}
|
|
1618
|
+
return;
|
|
1618
1619
|
}
|
|
1619
|
-
return;
|
|
1620
1620
|
}
|
|
1621
1621
|
|
|
1622
1622
|
// There's no need to abort on redirects, since we don't detect the
|
|
@@ -1988,7 +1988,7 @@ export function unstable_createStaticHandler(
|
|
|
1988
1988
|
}
|
|
1989
1989
|
|
|
1990
1990
|
let result = await queryImpl(request, location, matches);
|
|
1991
|
-
if (result
|
|
1991
|
+
if (isResponse(result)) {
|
|
1992
1992
|
return result;
|
|
1993
1993
|
}
|
|
1994
1994
|
|
|
@@ -2046,7 +2046,7 @@ export function unstable_createStaticHandler(
|
|
|
2046
2046
|
}
|
|
2047
2047
|
|
|
2048
2048
|
let result = await queryImpl(request, location, matches, match);
|
|
2049
|
-
if (result
|
|
2049
|
+
if (isResponse(result)) {
|
|
2050
2050
|
return result;
|
|
2051
2051
|
}
|
|
2052
2052
|
|
|
@@ -2087,7 +2087,7 @@ export function unstable_createStaticHandler(
|
|
|
2087
2087
|
}
|
|
2088
2088
|
|
|
2089
2089
|
let result = await loadRouteData(request, matches, routeMatch);
|
|
2090
|
-
return result
|
|
2090
|
+
return isResponse(result)
|
|
2091
2091
|
? result
|
|
2092
2092
|
: {
|
|
2093
2093
|
...result,
|
|
@@ -2616,7 +2616,7 @@ async function callLoaderOrAction(
|
|
|
2616
2616
|
request.signal.removeEventListener("abort", onReject);
|
|
2617
2617
|
}
|
|
2618
2618
|
|
|
2619
|
-
if (result
|
|
2619
|
+
if (isResponse(result)) {
|
|
2620
2620
|
let status = result.status;
|
|
2621
2621
|
|
|
2622
2622
|
// Process redirects
|
|
@@ -2627,14 +2627,11 @@ async function callLoaderOrAction(
|
|
|
2627
2627
|
"Redirects returned/thrown from loaders/actions must have a Location header"
|
|
2628
2628
|
);
|
|
2629
2629
|
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
let currentOrigin = currentUrl.origin;
|
|
2633
|
-
let newOrigin = new URL(location, currentOrigin).origin;
|
|
2634
|
-
let external = newOrigin !== currentOrigin;
|
|
2630
|
+
let isAbsolute =
|
|
2631
|
+
/^[a-z+]+:\/\//i.test(location) || location.startsWith("//");
|
|
2635
2632
|
|
|
2636
2633
|
// Support relative routing in internal redirects
|
|
2637
|
-
if (!
|
|
2634
|
+
if (!isAbsolute) {
|
|
2638
2635
|
let activeMatches = matches.slice(0, matches.indexOf(match) + 1);
|
|
2639
2636
|
let routePathnames = getPathContributingMatches(activeMatches).map(
|
|
2640
2637
|
(match) => match.pathnameBase
|
|
@@ -2642,7 +2639,7 @@ async function callLoaderOrAction(
|
|
|
2642
2639
|
let resolvedLocation = resolveTo(
|
|
2643
2640
|
location,
|
|
2644
2641
|
routePathnames,
|
|
2645
|
-
|
|
2642
|
+
new URL(request.url).pathname
|
|
2646
2643
|
);
|
|
2647
2644
|
invariant(
|
|
2648
2645
|
createPath(resolvedLocation),
|
|
@@ -2673,7 +2670,6 @@ async function callLoaderOrAction(
|
|
|
2673
2670
|
status,
|
|
2674
2671
|
location,
|
|
2675
2672
|
revalidate: result.headers.get("X-Remix-Revalidate") !== null,
|
|
2676
|
-
external,
|
|
2677
2673
|
};
|
|
2678
2674
|
}
|
|
2679
2675
|
|
|
@@ -3052,8 +3048,18 @@ function isRedirectResult(result?: DataResult): result is RedirectResult {
|
|
|
3052
3048
|
return (result && result.type) === ResultType.redirect;
|
|
3053
3049
|
}
|
|
3054
3050
|
|
|
3051
|
+
function isResponse(value: any): value is Response {
|
|
3052
|
+
return (
|
|
3053
|
+
value != null &&
|
|
3054
|
+
typeof value.status === "number" &&
|
|
3055
|
+
typeof value.statusText === "string" &&
|
|
3056
|
+
typeof value.headers === "object" &&
|
|
3057
|
+
typeof value.body !== "undefined"
|
|
3058
|
+
);
|
|
3059
|
+
}
|
|
3060
|
+
|
|
3055
3061
|
function isRedirectResponse(result: any): result is Response {
|
|
3056
|
-
if (!(result
|
|
3062
|
+
if (!isResponse(result)) {
|
|
3057
3063
|
return false;
|
|
3058
3064
|
}
|
|
3059
3065
|
|
|
@@ -3065,7 +3071,7 @@ function isRedirectResponse(result: any): result is Response {
|
|
|
3065
3071
|
function isQueryRouteResponse(obj: any): obj is QueryRouteResponse {
|
|
3066
3072
|
return (
|
|
3067
3073
|
obj &&
|
|
3068
|
-
obj.response
|
|
3074
|
+
isResponse(obj.response) &&
|
|
3069
3075
|
(obj.type === ResultType.data || ResultType.error)
|
|
3070
3076
|
);
|
|
3071
3077
|
}
|