@wix/headless-stores 0.0.47 → 0.0.48

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.
@@ -141,21 +141,17 @@ function updateUrlWithSearchState(searchState) {
141
141
  }
142
142
  // Handle URL path construction with category
143
143
  let baseUrl = window.location.pathname;
144
- // If categorySlug is provided, update the path
144
+ // If categorySlug is provided, replace the last path segment (which represents the category)
145
145
  if (categorySlug) {
146
- // Find if there's already a /category/ segment in the current path
147
146
  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;
147
+ if (pathSegments.length > 0) {
148
+ // Replace the last segment with the new category slug
149
+ pathSegments[pathSegments.length - 1] = categorySlug;
152
150
  baseUrl = "/" + pathSegments.join("/");
153
151
  }
154
152
  else {
155
- // Append category path to existing base
156
- baseUrl = baseUrl.endsWith("/")
157
- ? `${baseUrl}category/${categorySlug}`
158
- : `${baseUrl}/category/${categorySlug}`;
153
+ // If no segments, just use the category slug
154
+ baseUrl = `/${categorySlug}`;
159
155
  }
160
156
  }
161
157
  // Build the new URL
@@ -141,21 +141,17 @@ function updateUrlWithSearchState(searchState) {
141
141
  }
142
142
  // Handle URL path construction with category
143
143
  let baseUrl = window.location.pathname;
144
- // If categorySlug is provided, update the path
144
+ // If categorySlug is provided, replace the last path segment (which represents the category)
145
145
  if (categorySlug) {
146
- // Find if there's already a /category/ segment in the current path
147
146
  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;
147
+ if (pathSegments.length > 0) {
148
+ // Replace the last segment with the new category slug
149
+ pathSegments[pathSegments.length - 1] = categorySlug;
152
150
  baseUrl = "/" + pathSegments.join("/");
153
151
  }
154
152
  else {
155
- // Append category path to existing base
156
- baseUrl = baseUrl.endsWith("/")
157
- ? `${baseUrl}category/${categorySlug}`
158
- : `${baseUrl}/category/${categorySlug}`;
153
+ // If no segments, just use the category slug
154
+ baseUrl = `/${categorySlug}`;
159
155
  }
160
156
  }
161
157
  // Build the new URL
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-stores",
3
- "version": "0.0.47",
3
+ "version": "0.0.48",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "prebuild": "cd ../media && yarn build && cd ../ecom && yarn build",