我在下面創建的路由,story/new
未顯示它的story-new.html
模板。它總是去story-view.html
,因爲我得到了動態:storyID
所以new
認爲是一個動態名稱。如何在Angularjs中結合動態路由和靜態路由
如何合併它們使/new
將路由到story-new.html
或者我的路由結構出錯了?
$routeProvider.when('/story/new', {
templateUrl: 'js/modules/story-new/story-new.html'
});
$routeProvider.when('/story/:storyID', {
templateUrl: 'js/modules/story-view/story-view.html'
});
OMG,魔術!這工作。 我給你投票最短的答案在Stackoverflow。 – vzhen
是的它的工作原理,但我不完全確定爲什麼。想知道當Angular通過所有路線時我的實際邏輯是什麼(我猜它試圖匹配你最後定義的路線)。此外,爲什麼@ madhured的答案工作? – NicolasMoise
由於madhured在routeProvider的末尾定義了'otherwise'? – vzhen