2017-07-20 88 views
0

注:pushState的啓用奧裏利亞路線匹配

我有關於奧裏利亞路線匹配的問題/問題。我在app.ts以下途徑:

{ 
    route: ['profile'], 
    href: '#', 
    name: 'profile', 
    moduleId: PLATFORM.moduleName('../pages/profile', 'profile'), 
    title: 'Profile' 
}, 
{ 
    route: [':continents/:countries'], 
    name: 'countries', 
    moduleId: PLATFORM.moduleName('../pages/countries', 'countries'), 
    title: 'Countries' 
} 

profile.ts模塊,我做的是另configRoute,在這裏我設置另外2個路由,如:

{ 
    route: ['personal'], 
    href: '#', 
    name: 'personal', 
    moduleId: PLATFORM.moduleName('./personal', 'personal'), 
    title: 'Personal' 
}, 
{ 
    route: ['skills'], 
    href: '#', 
    name: 'skills', 
    moduleId: PLATFORM.moduleName('./skills', 'skills'), 
    title: 'Skills' 
} 

問題是:當我導航到/profile/skills/profile/personal時,該路線將匹配國家之一(':continents/:countries')。我認爲這是有道理的,因爲整個部分匹配。

我可以在配置文件路徑更改爲

{ 
    route: ['profile', 'profile/:tabName'], 
    href: '#', 
    name: 'profile', 
    moduleId: PLATFORM.moduleName('../pages/profile', 'profile'), 
    title: 'Profile' 
}, 

但後來我的路線會像/profile/personal/personal/profile/personal/skills我不想要的。

我試圖添加通配符作爲奧裏利亞文檔建議:

{ 
    route: ['profile', 'profile/*tabName'], 
    href: '#', 
    name: 'profile', 
    moduleId: PLATFORM.moduleName('../pages/profile', 'profile'), 
    title: 'Profile' 
}, 

但像/profile/skills路線不匹配它,它仍然去了':continents/:countries'

我能以某種方式強制它進入profile頁面嗎? (除子路由'countries'

回答

2

主應用程序路由器在嘗試匹配路由字符串時獲得第一個匹配,而profile/skills匹配':continents/:countries'

':continents/:countries'等同於.+/.+作爲路由正則表達式。它幾乎可以匹配任何字符串,並在其中間使用斜槓。

您需要在該路線中添加諸如'earth/:continents/:countries'之類的內容。在開始的時候添加一些硬編碼的字符串使其不再包含所有內容。

+0

是的,這是我現在的最後一招:)。謝謝您的意見。儘管如此,使它參數化('profile /:tabName')使得它攔截了預期的路線(配置文件,雖然有一個搞砸的url),通配符卻沒有? – Zubzob

+0

如果你告訴路由器尋找一個參數,那麼它會查找'profile /.+' –

+0

最終結果是':foo /:bar'類型的路由不適合你你的根路由器。 –