1
votes

May I know how to implement this custom route in spartacus ? product/:productCode/:name/order-form

I tried implementing this in my custom order-form-routes.module.ts But it doesn't seem to recognize this config as it throws a Page Not Found error.

ConfigModule.withConfig({
  routing: {
    routes: {
      orderForm: {
        paths: ['product/:code/:name/order-form'],
        paramsMapping: { code: 'code', name: 'name' },
      },
    },
  },
}),
1
Is it a product page or a content page? If a content page, please see sap.github.io/spartacus-docs/adding-and-customizing-routes/… . If a product page, please use :productCode instead of :code (because PDP are recognized only by the existence of the :prodcutCode param - by convention). Then drop your paramsMapping for code. By the way... paramsMapping for name is redundant in your example and can be dropped anyway.Krzysztof Platis
Its a ContentPage.. so I have tried your suggestion. But I can only load this custom route /order-form/:productCode/:name while I cannot seem to make the required /product/:productCode/:name/order-form work. Is it because, the URL is expecting to load a Product Page, instead of a Content Page? I get a 404 Page Not Found error for the latter.NAR

1 Answers

1
votes

considering @Platonn's suggestion: This config made it work:

RouterModule.forChild([
  {
    path: 'product/:code/:name/order-form',
    canActivate: [AuthGuard, CmsPageGuard],
    component: PageLayoutComponent,
    data: { pageLabel: '/order-form' },
  },
]),