Search code examples
spartacus-storefront

PDP Custom Routes defined in a module not working


I'm following the Spartacus bootcamp sample for routing https://github.com/SAP/spartacus-bootcamp/tree/77b7474c9538eaa1032062ad3c6d461fb1fc7517/src/app/features/routing

My problem is when I have configured the custom PDP

imports: [
    CommonModule,
    // dependent module for semantic URLs like cxUrl
    UrlModule,
    // standard non-spartacus routes
    RouterModule.forChild(staticRoutes),
    // configure product routes
    ConfigModule.withConfig({
      routing: {
        routes: {
          product: {
            paths: [
              'product/:manufacturer/:firstCategoryName/:productCode/:prettyName',
              'product/:manufacturer/:productCode/:prettyName',
              'product/:productCode/:name',
            ],
          },
        },
      },
    } as RoutingConfig),
    //code mapping in the routes
    ConfigModule.withConfig({
      paramsMapping: {
        productCode: 'code',
      },
    } as RouteConfig),

The new PDP routes are never used in the Storefront. I can see in the browser console that the custom product properties firstCategoryName and prettyName are properly settled from the normalizers/converters of the sample...

Any insight what can be going on?

Thanks!

Fernando


Solution

  • I think it will also depend on whether/not the manufacturer property is populated as well. By default the manufacturer field is not requested in the productSearch OCC call, so will not be populated on the product object (see default-occ-product-config.ts in the Spartacus code) - this means that on product listing pages (category & search) those two paths will not resolve, and are therefore ignored.