Angular, and Spartacus by extension, allows you to configure string patterns to match routes against URLs. An example is /product/:productCode, which has two segments. The first segment, product, is a static segment that determines the URL is a product page type, and the second segment, :productCode, is a dynamic parameter.
上面提到的url,有兩個segments,其中第一個product segment,為靜态segment,說明該url代表一個product page type,而第二個segment :productCode, 是一個動态參數。
有時存在需求,需要在一個segment内同時實作靜态和動态兩種segment:
However, there may be cases where you need to work with URL segments that contain both static and dynamic parts within a single segment. An example is /macbook-p, where mackbook is a dynamic product code, and -p is a static part that determines the URL is a product page type. In this case, you need to implement a custom Angular UrlMatcher.
這種需求通過UrlMatcher來滿足。
源代碼:

将自定義實作的matcher配置到module裡:
上面代碼中paths裡傳入的:customProductCode是一個新的屬性,需要通過normalizer添加進去:
最後将custom normalizer注入到app module中: