Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the following states:

$stateProvider.
            state('candidates', {
                abstract: true,
                url: '/candidates',
                templateUrl: '/Scripts/App/js/Views/candidates/candidates.html',
                controller: 'candidatesTableController'
            }).                
            state('candidates.item', {
                url: '/{item:[0-9]{1,4}}',
                templateUrl: '/Scripts/App/js/Views/candidates/candidate.html',
                controller: 'candidatesDetailController'
            }).
            state('candidates.item.details', {
                url: '/details',
                templateUrl: '/Scripts/App/js/Views/candidates/partials/generalDetails.html',
                controller: function($scope, $stateParams) {
                            $scope.item= $stateParams.item;
               }
            }).
            state('candidates.item.edit', {
                url: '/details/edit',
                templateUrl: '/Scripts/App/js/Views/candidates/partials/form.html',
                controller: function($scope, $stateParams) {
                            $scope.item = $stateParams.item;
                }
            }).state('candidates.item.photo', {
                url: '/details/photo',
                templateUrl: '/Scripts/App/js/Views/candidates/partials/updatePhotoID.html',
                controller: function($scope, $stateParams) {
                            $scope.item = $stateParams.item;
                }
            });

Here my urlRouterProvider:

$urlRouterProvider
            .when('/candidates/:item', '/candidates/:item/details')
            .otherwise("/");

When I use ui-sref everything work fine but when i using the actual url, it never can find the following url:

"/#/candidates/4/details"

it redirect to the root ("/#/")

I can't figure out why?

Thanks

share|improve this question

1 Answer 1

I created a plunkr with your routes defined here: http://run.plnkr.co/Sn3s7ooM6MOSxQnB/#/candidates/4/details

Code visible here: http://plnkr.co/edit/wArFenIZ7j3WczUhtJO6

Notice that the first link in this answer takes you right to the details page for a candidate item. Maybe you can figure out from my simplified code what it is that you need to change to achieve the same behavior.

Also, I noticed that your redirect doesn't work (the second nav item in my plunker allows you to go to this state without a redirect; try clicking it yourself):

.when('/candidates/:item', '/candidates/:item/details')

This redirect will work if you set the candidates.item state to be abstract. Maybe this is what you want.

See this in action here: http://plnkr.co/edit/y9LI0OKGMStVnMY2NX5q

Code visible here: http://plnkr.co/edit/y9LI0OKGMStVnMY2NX5q

I hope that helps

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.