@remix-run/router 1.3.0-pre.2 → 1.3.0

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/router.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.3.0-pre.2
2
+ * @remix-run/router v1.3.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -2507,7 +2507,7 @@ function createRouter(init) {
2507
2507
  } : {}));
2508
2508
  invariant(redirectLocation, "Expected a location on the redirect navigation"); // Check if this an external redirect that goes to a new origin
2509
2509
 
2510
- if (typeof ((_window = window) == null ? void 0 : _window.location) !== "undefined") {
2510
+ if (isBrowser && typeof ((_window = window) == null ? void 0 : _window.location) !== "undefined") {
2511
2511
  let newOrigin = init.history.createURL(redirect.location).origin;
2512
2512
 
2513
2513
  if (window.location.origin !== newOrigin) {
@@ -2987,7 +2987,7 @@ function createStaticHandler(routes, opts) {
2987
2987
  let location = createLocation("", createPath(url), null, "default");
2988
2988
  let matches = matchRoutes(dataRoutes, location, basename); // SSR supports HEAD requests while SPA doesn't
2989
2989
 
2990
- if (!isValidMethod(method) && method !== "head") {
2990
+ if (!isValidMethod(method) && method !== "head" && method !== "options") {
2991
2991
  throw getInternalRouterError(405, {
2992
2992
  method
2993
2993
  });
@@ -3503,6 +3503,16 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
3503
3503
  }
3504
3504
 
3505
3505
  location = createPath(resolvedLocation);
3506
+ } else if (!isStaticRequest) {
3507
+ // Strip off the protocol+origin for same-origin absolute redirects.
3508
+ // If this is a static reques, we can let it go back to the browser
3509
+ // as-is
3510
+ let currentUrl = new URL(request.url);
3511
+ let url = location.startsWith("//") ? new URL(currentUrl.protocol + location) : new URL(location);
3512
+
3513
+ if (url.origin === currentUrl.origin) {
3514
+ location = url.pathname + url.search + url.hash;
3515
+ }
3506
3516
  } // Don't process redirects in the router during static requests requests.
3507
3517
  // Instead, throw the Response and let the server handle it with an HTTP
3508
3518
  // redirect. We also update the Location header in place in this flow so