2012-10-08 26 views

回答

7

它值得一提的還有,除了ui-router另一個角度庫來完成這個任務。這其中也工作:

http://angular-route-segment.com

這是很簡單的UI相比,路由器使用。樣本路由配置是這樣的:

$routeSegmentProvider. 

when('/section1',   's1.home'). 
when('/section1/prefs', 's1.prefs'). 
when('/section1/:id',  's1.itemInfo.overview'). 
when('/section1/:id/edit', 's1.itemInfo.edit'). 
when('/section2',   's2'). 

segment('s1', { 
    templateUrl: 'templates/section1.html', 
    controller: MainCtrl}). 

within(). 

    segment('home', { 
     templateUrl: 'templates/section1/home.html'}). 

    segment('itemInfo', { 
     templateUrl: 'templates/section1/item.html', 
     controller: Section1ItemCtrl, 
     dependencies: ['id']}). 

    within(). 

     segment('overview', { 
      templateUrl: 'templates/section1/item/overview.html'}). 

     segment('edit', { 
      templateUrl: 'templates/section1/item/edit.html'}). 

     up(). 

    segment('prefs', { 
     templateUrl: 'templates/section1/prefs.html'}). 

    up(). 

segment('s2', { 
    templateUrl: 'templates/section2.html', 
    controller: MainCtrl}); 
+0

在這個例子中,section.html會被擊中嗎? '/ section1'路由到s1 ..家庭段,對吧?如果我是對的,那麼在s1段中定義一個templateUrl會導致誤導。那麼問題...... s1段的MainCtrl成爲'Section1ItemCtrl'的父控制器嗎? – Suamere

+1

它是一個嵌套視圖層次結構。 'home.html'包含在'section1.html'中,等等。所有控制器都在原型範圍鏈內。你可以在這裏看到這個例子:http://angular-route-segment.com/src/example/ – artch