3

I would like to use $location.path to do a redirect in angularjs. I have the following config:

ngModule.config(['$stateProvider', '$urlRouterProvider',
    function ($stateProvider, $urlRouterProvider) {
        $urlRouterProvider.otherwise('/');

        // Note: when adding a templateUrl, ensure that it's not a redirect but the full URL
        $stateProvider
            .state('logged-off', {
                url: '/logged_off',
                templateUrl: function () {
                    return '/partials/logged_off/';
                }
            });
   }]);

Then :

$location.path('logged_off'); works fine, but I would like to refer to the state (so logged-off in this case) instead of the url. How can I do that ?

1 Answer 1

3

Is it mandatory to use $location?

Have you tried $state.go?

$state.go('logged_of');
Sign up to request clarification or add additional context in comments.

1 Comment

I did try it, but I didn't put a condition based on the toState, so I was in an infinity loop :). Thanks

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.