From fd613e5a7d1826712efc2b98b4d45e79cf9ff2e9 Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Tue, 12 Apr 2022 17:07:21 +0200 Subject: [PATCH] fixed publishLocation --- src/components/App.svelte | 1 - src/index.ts | 16 ++++++++-------- src/store.ts | 2 -- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/components/App.svelte b/src/components/App.svelte index e52caf3..9d00d14 100644 --- a/src/components/App.svelte +++ b/src/components/App.svelte @@ -11,7 +11,6 @@ $location = { path: l[0], search: l.length > 1 ? l[1] : "", - categoryPath: l[0].replace(/\/\d{4,99}[^\/]+$/, ""), push: false, pop: false, } diff --git a/src/index.ts b/src/index.ts index 6b21075..4c36f51 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,10 @@ console.log("API Base: ", apiBaseURL) // update location store const publishLocation = (_p?: string) => { + const push = !!_p + if (!_p && typeof window !== "undefined") { + _p = window.location?.pathname + window.location?.search + } let _s: string if (_p) { const parts = _p.split("?") @@ -15,15 +19,11 @@ const publishLocation = (_p?: string) => { } const newLocation = { - path: - _p || (typeof window !== "undefined" && window.location?.pathname), - search: - _s || (typeof window !== "undefined" && window.location?.search), - push: !!_p, - pop: !_p, - categoryPath: "", + path: _p, + search: _s, + push, + pop: !push, } - newLocation.categoryPath = newLocation.path.replace(/\/\d{4,99}[^\/]+$/, "") location.set(newLocation) } diff --git a/src/store.ts b/src/store.ts index c8342cc..3558e73 100644 --- a/src/store.ts +++ b/src/store.ts @@ -6,9 +6,7 @@ const initLoc = { search: (typeof window !== "undefined" && window.location?.search) || "", push: false, pop: false, - categoryPath: "", } -initLoc.categoryPath = initLoc.path.replace(/\/\d{4,99}[^\/]+$/, "") export const location = writable(initLoc)