fixed publishLocation
This commit is contained in:
16
src/index.ts
16
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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user