需求
https://*.com/questions/59950572/how-to-access-the-current-categorydata-in-a-category-page
实现原理
AFAIK, currently we do not have anything similar to CurrentProductService for current category.
当前 SAP Spartacus 标准实现里,缺乏类似 CurrentProductService 对产品明细页面那样的支持。
Looking at the implementation of CurrentProductService you can see that it is using RoutingService and it's getRouterState() method (picture 1).
研究 CurrentProductService 的实现代码,发现其实现原理是,首先利用 RoutingService,从 RouterState 中拿到当前页面的产品code,然后使用另一个API,productService, 来读取产品的明细数据。
You can create something similar for current category, because the router state consists of category informations (as seen below on picture 2).
因此我们可以采取类似的思路,从 category 页面的State里,提取出category明细信息:
- categoryCode
- param0, param1, param2
更多Jerry的原创文章,尽在:"汪子熙":