artch/angular-route-segment

Route grouping without `.within()`

Closed this issue · 1 comments

With the routing table

$routeSegmentProvider
        .when('/articles/:id', 'article.info')
        .when('/articles/:id/text', 'article.text')
        .when('/articles/:id/annotations', 'article.annotations')
        .when('/articles/:id/annotations/new', 'article.annotations-new')
        .when('/articles/:id/annotations/:num', 'article.annotation-single')

(compare with issue #79) I would like to make a list item active whenever any of the annotation routes is active. Right now, I'm doing

  <li role="presentation" ng-class="{active:                                    
  ('article.annotations' | routeSegmentStartsWith)                              
  || ('article.annotations-new' | routeSegmentStartsWith)                       
  || ('article.annotations-single' | routeSegmentStartsWith)                    
  }">

which gets messier when adding new annotation routes. We cannot use subroutes (.within()) since all respective templates must display in the same view.

Is is possible to group the routes in any other way?

artch commented

'article.annotations' | routeSegmentStartsWith should be enough here, as it checks for the substring value lexically, without parsing it into segments splitted by dots. article.annotations is the substring of article.annotations-new as well.