Skip to content

Commit 2f95ce9

Browse files
Merge pull request #119 from vugar005/feature/connectrouter-add-query-params-support
connectRouter: add query params support
2 parents 78916f6 + cf8e2cd commit 2f95ce9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

libs/mf-tools/src/lib/web-components/router-utils.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@ export function endsWith(prefix: string): UrlMatcher {
2020
};
2121
}
2222

23-
export function connectRouter(router: Router, useHash = false) {
23+
export function connectRouter(router: Router, useHash = false): void {
24+
let url: string;
2425
if (!useHash) {
25-
router.navigateByUrl(location.pathname.substr(1));
26+
url = `${location.pathname.substr(1)}${location.search}`;
27+
router.navigateByUrl(url);
2628
window.addEventListener('popstate', () => {
27-
router.navigateByUrl(location.pathname.substr(1));
29+
router.navigateByUrl(url);
2830
});
2931
}
3032
else {
31-
router.navigateByUrl(location.hash.substr(1));
33+
url = `${location.hash.substr(1)}${location.search}`;
34+
router.navigateByUrl(url);
3235
window.addEventListener('hashchange', () => {
33-
router.navigateByUrl(location.hash.substr(1));
36+
router.navigateByUrl(url);
3437
});
3538
}
3639
}

0 commit comments

Comments
 (0)