From 7c90911a961f874b3a761f1cbba2db7c51559f23 Mon Sep 17 00:00:00 2001 From: Marco Botto Date: Sat, 14 Jan 2017 17:43:01 +0100 Subject: [PATCH] fix(pushStateLocation): call listeners in url() (#24) call all event listeners in url() after pushing/replacing the history state to correctly sync the router Closes #23 --- src/vanilla/pushStateLocation.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vanilla/pushStateLocation.ts b/src/vanilla/pushStateLocation.ts index cb9e26f5..6f32a00b 100644 --- a/src/vanilla/pushStateLocation.ts +++ b/src/vanilla/pushStateLocation.ts @@ -49,6 +49,9 @@ export class PushStateLocationService implements LocationServices, Disposable { let fullUrl = this._config.baseHref() + url; if (replace) this._history.replaceState(state, null, fullUrl); else this._history.pushState(state, null, fullUrl); + let evt = new Event("locationchange"); + evt['url'] = fullUrl; + this._listeners.forEach(cb => cb(evt)); } return buildUrl(this); @@ -56,7 +59,8 @@ export class PushStateLocationService implements LocationServices, Disposable { onChange(cb: EventListener) { window.addEventListener("popstate", cb, false); - return pushTo(this._listeners, () => window.removeEventListener("popstate", cb)); + this._listeners.push(cb); + return () => window.removeEventListener("popstate", cb); } dispose(router: UIRouter) {