我在代码库中看到了这一点:
.state('product', {
url: productPageUrl + '/:slug',
params: {
productId: null,
color: null,
size: null,
product: null
},
...
},
...
这是什么意思?
/
之后的所有数据都是slug,对吧?
但是访问$ stateParams ['productId']会返回正确的id。 ex:for url:
/product/product-name-homme-170758.html
为170758
返回$stateParams['productId']
。
答案 0 :(得分:2)
params
定义非URL路由参数。它们只是不会出现在URL中。在您的情况下,slug
应该等于product-name-homme-170758.html
,而productId
只需设置为ui-sref
或$state.go
在您的示例中,它将是:
ui-sref="product({ slug: 'product-name-homme-170758.html', productId: 170758 })"