Skip to content

Commit

Permalink
fix(pushStateLocation): call listeners in url() (#24)
Browse files Browse the repository at this point in the history
call all event listeners in url() after pushing/replacing the history state to correctly sync the router

Closes #23
  • Loading branch information
elboman authored and christopherthielen committed Jan 14, 2017
1 parent 588dd99 commit 7c90911
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/vanilla/pushStateLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,18 @@ 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);
}

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) {
Expand Down

0 comments on commit 7c90911

Please sign in to comment.