2016-11-23 27 views
0

當我輸入網址「/ samsung」時,我不知道應該使用什麼狀態,因此它只會匹配此案例類別中的第一個。如何在ui-router中重定向到正確的狀態?

我已經做了一些閱讀,我的事情我應該使用UrlMatcher,然後根據重定向到適當的狀態......但如何?

https://ui-router.github.io/docs/latest/classes/url.urlmatcher.html

我有4個州。

const home = { 
    name: 'home', 
    url: '/', 
    component: 'home' 
}; 

const category = { 
    name: 'home.category', 
    url: '{categoryName}', 
    component: 'category' 
}; 

const product = { 
    name: 'home.category.product', 
    url: '{productName}', 
    component: 'product' 
}; 

const cmsPage = { 
    name: 'home.cmsPage', 
    url: '{pageTitle}', 
    component: 'cmsPage' 
}; 

我有一個服務,可以爲我提供一個基於URL的頁面類型。

所以使用該服務與參數「三星」將給予「類別」和「銀河」將給予「產品」等的反應...

回答

0

除了回家。所有其他路由URL定義爲url:'variable-name'。但是,它應該是url: '/route-name/variable-name'。類似的,

const category = { 
     name: 'home.category', 
     url: '/category/:{categoryName}', 
     component: 'category' 
    }; 
相關問題