2016-05-17 80 views
2

我已经看到了这个在基本代码:具有`params`参数的基本参数。 UI - 路由器

.state('product', { 
    url: productPageUrl + '/:slug', 
    params: { 
     productId: null, 
     color: null, 
     size: null, 
     product: null 
    }, 
    ... 
}, 
... 

是什么意思? /之后的所有数据都会显示为slug,对不起? 但访问$ stateParams ['productId']返回正确的ID。例如:对于网址:

/product/product-name-homme-170758.html 

$stateParams['productId']回报170758

回答

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 })" 
+0

谢谢你,所以如果我重新加载状态,我可以”不知道那个产品是什么。我想,唯一能做的就是从slu extract中提取它。对? –

+0

虽然我以前没有真正使用过'params',但我会说你完全正确。 –