新建一个Route module:
import { NgModule } from '@angular/core';
import { ConfigModule, OccConfig, RoutingConfig } from '@spartacus/core';
@NgModule({
declarations: [],
imports: [
ConfigModule.withConfig({
routing: {
routes: {
product: {
paths: [
'cameras/:productCode/:manufacturer/:name',
'cameras/:productCode/:name',
'cameras/:productCode/',
]
}
}
}
} as RoutingConfig),
ConfigModule.withConfig({
backend: {
occ: {
endpoints: {
productSearch:
// tslint:disable-next-line: max-line-length
'products/search?fields=products(code,manufacturer,name,summary,price(FULL),images(DEFAULT),stock(FULL),averageRating,variantOptions),facets,breadcrumbs,pagination(DEFAULT),sorts(DEFAULT),freeTextSearch,currentQuery',
},
},
},
} as OccConfig),
]
})
export class RoutingConfigurationModule { }
默认的路由url:product/productCode/productName

我在TypeScript代码里维护的路由url里,包含了硬编码的camera,如下所示:
camera/productCode/productName
启用我自定义的路由module之后,运行时效果:

另一种包含了manufactor code的url:

这是因为我在api endpoint里,指定了将manufacturer字段一并取回:

更多Jerry的原创文章,尽在:"汪子熙":

网友评论