2012-10-08 24 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