fixed publishLocation
This commit is contained in:
parent
ef8d571ac5
commit
fd613e5a7d
@ -11,7 +11,6 @@
|
|||||||
$location = {
|
$location = {
|
||||||
path: l[0],
|
path: l[0],
|
||||||
search: l.length > 1 ? l[1] : "",
|
search: l.length > 1 ? l[1] : "",
|
||||||
categoryPath: l[0].replace(/\/\d{4,99}[^\/]+$/, ""),
|
|
||||||
push: false,
|
push: false,
|
||||||
pop: false,
|
pop: false,
|
||||||
}
|
}
|
||||||
|
16
src/index.ts
16
src/index.ts
@ -6,6 +6,10 @@ console.log("API Base: ", apiBaseURL)
|
|||||||
|
|
||||||
// update location store
|
// update location store
|
||||||
const publishLocation = (_p?: string) => {
|
const publishLocation = (_p?: string) => {
|
||||||
|
const push = !!_p
|
||||||
|
if (!_p && typeof window !== "undefined") {
|
||||||
|
_p = window.location?.pathname + window.location?.search
|
||||||
|
}
|
||||||
let _s: string
|
let _s: string
|
||||||
if (_p) {
|
if (_p) {
|
||||||
const parts = _p.split("?")
|
const parts = _p.split("?")
|
||||||
@ -15,15 +19,11 @@ const publishLocation = (_p?: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newLocation = {
|
const newLocation = {
|
||||||
path:
|
path: _p,
|
||||||
_p || (typeof window !== "undefined" && window.location?.pathname),
|
search: _s,
|
||||||
search:
|
push,
|
||||||
_s || (typeof window !== "undefined" && window.location?.search),
|
pop: !push,
|
||||||
push: !!_p,
|
|
||||||
pop: !_p,
|
|
||||||
categoryPath: "",
|
|
||||||
}
|
}
|
||||||
newLocation.categoryPath = newLocation.path.replace(/\/\d{4,99}[^\/]+$/, "")
|
|
||||||
location.set(newLocation)
|
location.set(newLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,7 @@ const initLoc = {
|
|||||||
search: (typeof window !== "undefined" && window.location?.search) || "",
|
search: (typeof window !== "undefined" && window.location?.search) || "",
|
||||||
push: false,
|
push: false,
|
||||||
pop: false,
|
pop: false,
|
||||||
categoryPath: "",
|
|
||||||
}
|
}
|
||||||
initLoc.categoryPath = initLoc.path.replace(/\/\d{4,99}[^\/]+$/, "")
|
|
||||||
|
|
||||||
export const location = writable(initLoc)
|
export const location = writable(initLoc)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user