@@ -662,8 +662,6 @@ export const IDLE_BLOCKER: BlockerUnblocked = {
662662
663663const ABSOLUTE_URL_REGEX = / ^ (?: [ a - z ] [ a - z 0 - 9 + . - ] * : | \/ \/ ) / i;
664664
665- const globalWindow = typeof window !== "undefined" ? window : undefined ;
666-
667665const defaultMapRouteProperties : MapRoutePropertiesFunction = ( route ) => ( {
668666 hasErrorBoundary : Boolean ( route . hasErrorBoundary ) ,
669667} ) ;
@@ -677,14 +675,16 @@ const defaultMapRouteProperties: MapRoutePropertiesFunction = (route) => ({
677675/**
678676 * Create a router and listen to history POP navigations
679677 */
680- export function createRouter ( {
681- window = globalWindow ,
682- ...init
683- } : RouterInit ) : Router {
678+ export function createRouter ( init : RouterInit ) : Router {
679+ const routerWindow = init . window
680+ ? init . window
681+ : typeof window !== "undefined"
682+ ? window
683+ : undefined ;
684684 const isBrowser =
685- typeof window !== "undefined" &&
686- typeof window . document !== "undefined" &&
687- typeof window . document . createElement !== "undefined" ;
685+ typeof routerWindow !== "undefined" &&
686+ typeof routerWindow . document !== "undefined" &&
687+ typeof routerWindow . document . createElement !== "undefined" ;
688688 const isServer = ! isBrowser ;
689689
690690 invariant (
@@ -2088,19 +2088,15 @@ export function createRouter({
20882088 "Expected a location on the redirect navigation"
20892089 ) ;
20902090 // Check if this an absolute external redirect that goes to a new origin
2091- if (
2092- ABSOLUTE_URL_REGEX . test ( redirect . location ) &&
2093- isBrowser &&
2094- typeof window ?. location !== "undefined"
2095- ) {
2091+ if ( ABSOLUTE_URL_REGEX . test ( redirect . location ) && isBrowser ) {
20962092 let url = init . history . createURL ( redirect . location ) ;
20972093 let isDifferentBasename = stripBasename ( url . pathname , basename ) == null ;
20982094
2099- if ( window . location . origin !== url . origin || isDifferentBasename ) {
2095+ if ( routerWindow . location . origin !== url . origin || isDifferentBasename ) {
21002096 if ( replace ) {
2101- window . location . replace ( redirect . location ) ;
2097+ routerWindow . location . replace ( redirect . location ) ;
21022098 } else {
2103- window . location . assign ( redirect . location ) ;
2099+ routerWindow . location . assign ( redirect . location ) ;
21042100 }
21052101 return ;
21062102 }
0 commit comments