@wix/headless-stores 0.0.46 → 0.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -143,8 +143,19 @@ function updateUrlWithSearchState(searchState) {
|
|
|
143
143
|
let baseUrl = window.location.pathname;
|
|
144
144
|
// If categorySlug is provided, update the path
|
|
145
145
|
if (categorySlug) {
|
|
146
|
-
if
|
|
147
|
-
|
|
146
|
+
// Find if there's already a /category/ segment in the current path
|
|
147
|
+
const pathSegments = baseUrl.split("/").filter(Boolean);
|
|
148
|
+
const categoryIndex = pathSegments.findIndex((segment) => segment === "category");
|
|
149
|
+
if (categoryIndex !== -1) {
|
|
150
|
+
// Replace existing category slug
|
|
151
|
+
pathSegments[categoryIndex + 1] = categorySlug;
|
|
152
|
+
baseUrl = "/" + pathSegments.join("/");
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
// Append category path to existing base
|
|
156
|
+
baseUrl = baseUrl.endsWith("/")
|
|
157
|
+
? `${baseUrl}category/${categorySlug}`
|
|
158
|
+
: `${baseUrl}/category/${categorySlug}`;
|
|
148
159
|
}
|
|
149
160
|
}
|
|
150
161
|
// Build the new URL
|
|
@@ -143,8 +143,19 @@ function updateUrlWithSearchState(searchState) {
|
|
|
143
143
|
let baseUrl = window.location.pathname;
|
|
144
144
|
// If categorySlug is provided, update the path
|
|
145
145
|
if (categorySlug) {
|
|
146
|
-
if
|
|
147
|
-
|
|
146
|
+
// Find if there's already a /category/ segment in the current path
|
|
147
|
+
const pathSegments = baseUrl.split("/").filter(Boolean);
|
|
148
|
+
const categoryIndex = pathSegments.findIndex((segment) => segment === "category");
|
|
149
|
+
if (categoryIndex !== -1) {
|
|
150
|
+
// Replace existing category slug
|
|
151
|
+
pathSegments[categoryIndex + 1] = categorySlug;
|
|
152
|
+
baseUrl = "/" + pathSegments.join("/");
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
// Append category path to existing base
|
|
156
|
+
baseUrl = baseUrl.endsWith("/")
|
|
157
|
+
? `${baseUrl}category/${categorySlug}`
|
|
158
|
+
: `${baseUrl}/category/${categorySlug}`;
|
|
148
159
|
}
|
|
149
160
|
}
|
|
150
161
|
// Build the new URL
|