Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three level nested routes in angular-ui-router

Im trying to get my nested route working but it's giving me hard time for two days now :(

one level works fine

two levels works fine

three levels is not working!

can anybody please help me out?

Thanks in advance

angular.module('settings', []).config(['$stateProvider', '$routeProvider', '$urlRouterProvider', function($stateProvider, $routeProvider, $urlRouterProvider) {
    $stateProvider
        .state('settings', {
            url: '/settings',
           template:"Settings",
            controller: function(){
                console.log('settings');
            }
        }).
        state('settings.branch', {
            url: '/{branchId:[0-9]{1,8}}',
            template:"Branch",
            controller: function(){
                console.log('branch');
            }
        }).
        state('settings.branch.prop', {
            url: '/prop',
            template:"Property",
            controller: function(){
                console.log('property');
            }
        });
}]);

'/settings' is working

'/settings/1234' is working

'/settings/1234/prop' is not working, always return the prevues state 'Branch'

like image 479
Abod Avatar asked May 29 '13 19:05

Abod


People also ask

What is nested routing in Angular?

Nested routes are routes within other routes. In this tutorial, we will show you how to create a child route and display the child components. The Angular allows us to nest child routes under another child routes effectively creating a Tree of routes.

What is nested route?

Nested Routes are a powerful feature. While most people think React Router only routes a user from page to page, it also allows one to exchange specific fragments of the view based on the current route.

What is Children in Angular route?

In Angular, the router lets you add child routes using the children property inside the routing module. Here you can see that the routing module has been updated with the child route and added to the array of components so we do not need to import all of them wherever we go.


2 Answers

I guess you didn't declare an ui-view in the Branch template

like image 149
Florian F Avatar answered Oct 20 '22 15:10

Florian F


I had the same issue. For settings.branch.prop, try setting url to:

url: '/{branchId:[0-9]{1,8}}/prop'
like image 36
piotr.d Avatar answered Oct 20 '22 13:10

piotr.d