SAP Spartacus semantic route的paths是一個數組,可以容納多個paths記錄:
ConfigModule.withConfig({
routing: {
routes: {
product: {
paths: [
':campaignName/product/:productCode',
'product/:productCode'
]
}
}
}
})
1
2
3
4
5
6
7
8
9
10
11
12
Then a configurable router link will use the first configured path alias from the paths array that can satisfy its params with given params object. So it’s good to order aliases from those that require the most specific parametes to those having less parameters.
最佳實踐就是,路由路徑裡需要提供越多參數的route,應該越出現在paths數組的前部。
下面這種是錯誤的route alias配置方式,因為在productCode被提供的前提條件下,第一條記錄p/:productCode總是被優先比對,而第二條記錄永遠沒有機會得到應用。
