From cf8e2cdc22fa3b534e72030f3e040f939bfda8d6 Mon Sep 17 00:00:00 2001 From: Vugar_Abdullayev Date: Wed, 19 Jan 2022 12:15:37 +0100 Subject: [PATCH] connectrouter add query params support --- .../mf-tools/src/lib/web-components/router-utils.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/mf-tools/src/lib/web-components/router-utils.ts b/libs/mf-tools/src/lib/web-components/router-utils.ts index 8feac8e9..feb148e6 100644 --- a/libs/mf-tools/src/lib/web-components/router-utils.ts +++ b/libs/mf-tools/src/lib/web-components/router-utils.ts @@ -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); }); } } \ No newline at end of file