From 608b18b841a4994d751065eece4a1e8f56127db0 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 14 May 2019 13:56:18 +0200 Subject: [PATCH] refactor: change onpopstate to onhashchange --- src/leafeon.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/leafeon.ts b/src/leafeon.ts index 29e1acc..2cf71b6 100644 --- a/src/leafeon.ts +++ b/src/leafeon.ts @@ -30,11 +30,7 @@ class RouterRequest { * @returns {string} */ public getURI = (): string => { - if (typeof window !== 'undefined') { - return this.URI = this.formatPath(window.location.hash); - } else { - return this.URI = this.formatPath(this.windowObj.location.hash); - } + return this.URI = this.formatPath(this.windowObj.location.hash); } /** @@ -42,11 +38,7 @@ class RouterRequest { * @param route string */ public setURI = (route: string): void => { - if (typeof window !== 'undefined') { - window.location.hash = route; - } else { - this.windowObj.location.hash = route; - } + this.windowObj.location.hash = route; } /** @@ -76,12 +68,12 @@ class RouterRequest { } /** - * @function setURI + * @function windowListener * @param route string */ public windowListener = (callback: Function): void => { if (typeof window !== 'undefined') { - window.onpopstate = () => { + window.onhashchange = () => { callback(); }; }