2

In my application I am running a function after route-config. in the function i am checking the login status, and accordingly trying to redirecting to login page. But it's not working,

here is the function how i call :

angular.module('meanOffice') .config(routeConfig) .run(stateController); function stateController( $rootScope, auth, authToken, $state ){ $rootScope.$on("$stateChangeStart", function(){ var isLoggedIn = auth.isLoggedIn(); console.log( $state.current.url )// consoles as ^ if(!isLoggedIn) { $state.go('/'); // Could not resolve '/' from state '' } }) } 

How to fix this? what is wrong here? any one help me.

7
  • any errors ???? Commented Nov 17, 2016 at 12:56
  • see in comment, // Could not resolve '/' from state '' Commented Nov 17, 2016 at 13:01
  • check your state declaration and other invocations like attached js...when the router cant find the given state this will arises Commented Nov 17, 2016 at 13:09
  • I tried like this $state.go('login', {}); - there is no error exist. But my page is not redirected to login state, login state is exist already Commented Nov 17, 2016 at 13:12
  • try with $location.path('/login'); or $state.go('/login'); please update your states declaration Commented Nov 17, 2016 at 13:16

2 Answers 2

2

event.preventDefault()

this will cancel the current event like state changing.....suppose your going to home state with out login then event.preventDefault(); function cancle that and redirect to the given state in state.go

here you can find the clear demonsration for this functionality

Sign up to request clarification or add additional context in comments.

Comments

0

"// Could not resolve '/' from state '' " --this error is because there is no state with "/" is present in $stateProvider. Please include one. Had attached sample code for your reference

$stateProvider.state("/", { url: "/tpl.htmlpage.html", templateUrl: "htmlpage.html" }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.