@@ -346,23 +346,17 @@ export async function parseUrlToSearchOptions(
346
346
// Initialize search state for service
347
347
const initialSearchState : InitialSearchState = { } ;
348
348
349
- // Extract category slug from URL path (e.g., /category/category-slug)
350
- const pathSegments = urlObj . pathname . split ( "/" ) ;
351
- const categoryIndex = pathSegments . findIndex (
352
- ( segment ) => segment === "category" ,
353
- ) ;
354
- let categorySlug : string | null = null ;
349
+ // Extract category slug from URL path
350
+ // The category slug is always the last segment of the path
351
+ const pathSegments = urlObj . pathname . split ( "/" ) . filter ( Boolean ) ;
355
352
let category : Category | undefined = undefined ;
356
353
357
- if ( categoryIndex !== - 1 && categoryIndex + 1 < pathSegments . length ) {
358
- categorySlug = pathSegments [ categoryIndex + 1 ] || null ;
359
-
360
- // Find the category by slug from the provided categories list
361
- if ( categorySlug ) {
362
- category = categoriesList . find ( ( cat ) => cat . slug === categorySlug ) ;
363
- if ( category ) {
364
- initialSearchState . category = category ;
365
- }
354
+ if ( pathSegments . length > 0 ) {
355
+ const lastSegment = pathSegments [ pathSegments . length - 1 ] ;
356
+ // Check if the last segment matches any category in the categories list
357
+ category = categoriesList . find ( ( cat ) => cat . slug === lastSegment ) ;
358
+ if ( category ) {
359
+ initialSearchState . category = category ;
366
360
}
367
361
}
368
362
@@ -629,11 +623,16 @@ export async function parseUrlToSearchOptions(
629
623
* ```
630
624
*/
631
625
export async function loadProductsListSearchServiceConfig (
632
- input : string | { searchOptions : productsV3 . V3ProductSearch ; initialSearchState : InitialSearchState } ,
626
+ input :
627
+ | string
628
+ | {
629
+ searchOptions : productsV3 . V3ProductSearch ;
630
+ initialSearchState : InitialSearchState ;
631
+ } ,
633
632
) : Promise < ProductsListSearchServiceConfig > {
634
633
let initialSearchState : InitialSearchState ;
635
634
636
- if ( typeof input === ' string' ) {
635
+ if ( typeof input === " string" ) {
637
636
// URL input - parse it
638
637
const categoriesListConfig = await loadCategoriesListServiceConfig ( ) ;
639
638
const { initialSearchState : parsedState } = await parseUrlToSearchOptions (
0 commit comments