Skip to content

Commit

Permalink
Merge pull request #119 from vugar005/feature/connectrouter-add-query…
Browse files Browse the repository at this point in the history
…-params-support

connectRouter: add query params support
  • Loading branch information
manfredsteyer authored Feb 13, 2022
2 parents 78916f6 + cf8e2cd commit 2f95ce9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions libs/mf-tools/src/lib/web-components/router-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ export function endsWith(prefix: string): UrlMatcher {
};
}

export function connectRouter(router: Router, useHash = false) {
export function connectRouter(router: Router, useHash = false): void {
let url: string;
if (!useHash) {
router.navigateByUrl(location.pathname.substr(1));
url = `${location.pathname.substr(1)}${location.search}`;
router.navigateByUrl(url);
window.addEventListener('popstate', () => {
router.navigateByUrl(location.pathname.substr(1));
router.navigateByUrl(url);
});
}
else {
router.navigateByUrl(location.hash.substr(1));
url = `${location.hash.substr(1)}${location.search}`;
router.navigateByUrl(url);
window.addEventListener('hashchange', () => {
router.navigateByUrl(location.hash.substr(1));
router.navigateByUrl(url);
});
}
}

0 comments on commit 2f95ce9

Please sign in to comment.