2016-05-17 81 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',但我會說你完全正確。 –