Created
January 11, 2019 11:38
-
-
Save artemave/7c7415878c414cfdaf3978485d74e11d to your computer and use it in GitHub Desktop.
Stub window location for hyperdom router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isBrowser = typeof window !== 'undefined'; | |
var pushState, replaceState; | |
pushState = replaceState = function(state, title, url) { | |
window.location.pathname = url; | |
(window.__registeredEvents['onpopstate'] || []).forEach(cb => cb({})); | |
}; | |
if (!isBrowser) { | |
global.window = { | |
location: { | |
pathname: '/', | |
search: '' | |
}, | |
__registeredEvents: {}, | |
history: { | |
pushState, | |
replaceState, | |
}, | |
addEventListener(eventName, cb) { | |
if (!this.__registeredEvents[eventName]) { | |
this.__registeredEvents[eventName] = []; | |
} | |
this.__registeredEvents[eventName].push(cb); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment