9

I am new to angular, I want to know if angularjs supports nested routes like emberjs I mean routes like this: myappurl/#/company/:company_id/department/:department_id

3 Answers 3

7

It worth mentioning there are another Angular libraries except ui-router to accomplish this task. This one works too:

http://angular-route-segment.com

It is much simpler to use than ui-router. Sample route configuration looks like this:

$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});
Sign up to request clarification or add additional context in comments.

3 Comments

In the example, would section.html ever be hit? /section1 is routed to the s1 .. home segment, right? If I'm right, it is misleading to have a templateUrl defined in the s1 segment. Then the question... does the MainCtrl for the s1 segment become a parent controller to the Section1ItemCtrl?
It is a nested view hierarchy. home.html is included into section1.html, and so forth. All controllers are inside a prototypal scope chain. You can see this example live here: angular-route-segment.com/src/example
@artch how can u do this? I go Section1, then i go to Item 5 (inside section1), now i go to Section2, now i click on Section1(it reestar pages, BUT I WAMMA REOPEN ITEM5) im not sure if u understand what im saying
3

According to the example given in the document: https://docs.angularjs.org/api/ngRoute/directive/ngView. Yes, Angularjs supports it.

1 Comment

Thank you so much the frontend developer in my team was very happy :) we missed it.
3

It can also be worth checking out https://github.com/angular-ui/ui-router

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.