From 210d4c505824bd2db5d52b4b5b08e48f217897e6 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 14 Dec 2021 15:23:02 +0100 Subject: [PATCH] web: add helper to navigate with params Signed-off-by: Jens Langhammer --- web/src/elements/router/RouterOutlet.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/web/src/elements/router/RouterOutlet.ts b/web/src/elements/router/RouterOutlet.ts index 6a7bc852a..9329887ec 100644 --- a/web/src/elements/router/RouterOutlet.ts +++ b/web/src/elements/router/RouterOutlet.ts @@ -30,6 +30,19 @@ window.addEventListener("load", () => { })(); }); +export function paramURL(url: string, params?: { [key: string]: unknown }): string { + let finalUrl = "#"; + finalUrl += url; + if (params) { + finalUrl += ";"; + finalUrl += encodeURIComponent(JSON.stringify(params)); + } + return finalUrl; +} +export function navigate(url: string, params?: { [key: string]: unknown }): void { + window.location.assign(paramURL(url, params)); +} + @customElement("ak-router-outlet") export class RouterOutlet extends LitElement { @property({ attribute: false })