3gwebtrain 3gwebtrain - 1 year ago 67
AngularJS Question

`ui-route` - not able to redirect and not geting the `url` of current state

In my application I am running a function after

. 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 :


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.

Answer Source


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download