christopherthielen / ui-router-extras

THIS PROJECT IS NO LONGER MAINTAINED -- Extras for UI-Router for AngularJS. Sticky States (a.k.a. parallel states), Deep State Redirect (for tab-like navigation), Future States (async state definition)
http://christopherthielen.github.io/ui-router-extras/
MIT License
917 stars 211 forks source link

getting `infdig` when deepStateRedirect use with `$urlRouteProvider.otherwise` #246

Closed guy-mograbi-at-gigaspaces closed 8 years ago

guy-mograbi-at-gigaspaces commented 9 years ago

Hi,

I was trying to give a reasonable default route for my app.. following numerous links, for example : http://stackoverflow.com/questions/16793724/otherwise-on-stateprovider reached a code that looks like this :

.config(function ($stateProvider, $urlRouterProvider) {
        $stateProvider

            .state('deploy', {
                url: '/deploy',
                templateUrl: 'views/directives/base_layout.html',
                deepStateRedirect: { default: { state: 'deploy.cloud' } }
            })

            .state('deploy.cloud', {
                url: '/cloud',
                templateUrl: 'views/directives/deploy_layout.html',
                controller: 'DeployLayoutCtrl',
                deepStateRedirect: { default: { state: 'deploy.cloud.generalData' } }
            }, ... );

        $urlRouterProvider.otherwise('/deploy');

    })

the aim was to redirect / to state deploy and have state deploy redirect to deploy.cloud - this way if the default for deploy changes, everything remains consistent.

I was surprised to see that when I go to localhost:9000 (no path) - i see infinite redirects with error prints of infinite digest until it reaches.

This does not happen if I remove one of the two or if the otherwise points to a state without deepStateRedirect.

I am using angular 1.4.3 and angular-ui-router 0.2.15.

joeljeske commented 8 years ago

I am getting this same issue, even with just a single dsr state and an otherwise.

I was able to alleviate this issue by using the function form of the the otherwise function. Similar to

$urlRouterProvider.otherwise(function($injector, $location) {
  $injector.get('$state').go('deploy');
});

Does that work for you?

rmorlang commented 8 years ago

@joeljeske's suggested workaround resolves the issue for me. Thanks!

guy-mograbi-at-gigaspaces commented 8 years ago

yup - works for me too.. thanks.