@@ -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
- redirect . external &&
1611
- typeof window !== "undefined" &&
1612
- typeof window . location !== "undefined"
1613
- ) {
1614
- if ( replace ) {
1615
- window . location . replace ( redirect . location ) ;
1616
- } else {
1617
- window . location . assign ( redirect . location ) ;
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
@@ -2627,22 +2627,19 @@ async function callLoaderOrAction(
2627
2627
"Redirects returned/thrown from loaders/actions must have a Location header"
2628
2628
) ;
2629
2629
2630
- // Check if this an external redirect that goes to a new origin
2631
- let currentUrl = new URL ( request . url ) ;
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 ( ! external ) {
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
2641
2638
) ;
2642
2639
let resolvedLocation = resolveTo (
2643
2640
location ,
2644
2641
routePathnames ,
2645
- currentUrl . pathname
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
0 commit comments