@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/router",
3
- "version": "1.3.0-pre.2",
3
+ "version": "1.3.0",
4
4
  "description": "Nested/Data-driven/Framework-agnostic Routing",
5
5
  "keywords": [
6
6
  "remix",
package/router.ts CHANGED
@@ -1901,7 +1901,7 @@ export function createRouter(init: RouterInit): Router {
1901
1901
  );
1902
1902
 
1903
1903
  // Check if this an external redirect that goes to a new origin
1904
- if (typeof window?.location !== "undefined") {
1904
+ if (isBrowser && typeof window?.location !== "undefined") {
1905
1905
  let newOrigin = init.history.createURL(redirect.location).origin;
1906
1906
  if (window.location.origin !== newOrigin) {
1907
1907
  if (replace) {
@@ -2421,7 +2421,7 @@ export function createStaticHandler(
2421
2421
  let matches = matchRoutes(dataRoutes, location, basename);
2422
2422
 
2423
2423
  // SSR supports HEAD requests while SPA doesn't
2424
- if (!isValidMethod(method) && method !== "head") {
2424
+ if (!isValidMethod(method) && method !== "head" && method !== "options") {
2425
2425
  throw getInternalRouterError(405, { method });
2426
2426
  } else if (!matches) {
2427
2427
  throw getInternalRouterError(404, { pathname: location.pathname });
@@ -3115,6 +3115,17 @@ async function callLoaderOrAction(
3115
3115
  }
3116
3116
 
3117
3117
  location = createPath(resolvedLocation);
3118
+ } else if (!isStaticRequest) {
3119
+ // Strip off the protocol+origin for same-origin absolute redirects.
3120
+ // If this is a static reques, we can let it go back to the browser
3121
+ // as-is
3122
+ let currentUrl = new URL(request.url);
3123
+ let url = location.startsWith("//")
3124
+ ? new URL(currentUrl.protocol + location)
3125
+ : new URL(location);
3126
+ if (url.origin === currentUrl.origin) {
3127
+ location = url.pathname + url.search + url.hash;
3128
+ }
3118
3129
  }
3119
3130
 
3120
3131
  // Don't process redirects in the router during static requests requests.