Skip to content

Commit 7c90911

Browse files
elbomanchristopherthielen
authored andcommitted
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
1 parent 588dd99 commit 7c90911

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/vanilla/pushStateLocation.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,18 @@ export class PushStateLocationService implements LocationServices, Disposable {
4949
let fullUrl = this._config.baseHref() + url;
5050
if (replace) this._history.replaceState(state, null, fullUrl);
5151
else this._history.pushState(state, null, fullUrl);
52+
let evt = new Event("locationchange");
53+
evt['url'] = fullUrl;
54+
this._listeners.forEach(cb => cb(evt));
5255
}
5356

5457
return buildUrl(this);
5558
}
5659

5760
onChange(cb: EventListener) {
5861
window.addEventListener("popstate", cb, false);
59-
return pushTo(this._listeners, () => window.removeEventListener("popstate", cb));
62+
this._listeners.push(cb);
63+
return () => window.removeEventListener("popstate", cb);
6064
}
6165

6266
dispose(router: UIRouter) {

0 commit comments

Comments
 (0)