After login is successful, how to redirect to home page?

I have defined all the states in my app.js.

Here are app requirements

  1. always show login page when the user clicks the app.

  2. once login is successful, show home page. (shdn’t be viewing home page without login)

How I shd do this using the UI router ? what should be the default page in the UI router config function ?

.controller(‘LoginCtrl’, function($scope, $http, $log) {

$scope.onLoginButtonClick = function(){

var  postData = {
            "password": $scope.password,
            "username": $scope.username

$'http://login_URL', postData)
.success(function(data) {
.error(function(data) {



The above code dipicts my app flow… I am getting the login successful alert !!! after that how to redirect to home page state ?

tried $scope.state.go(‘home’); as above but didn’t work :frowning:

I use the following to redirect my sign in states:


Would that work for you?

router default page should be “login” in this occasion. Can you show a part of your UI router config? state.go “home” should trigger fine if your routes are setup correctly

I got it working by using $state.go(‘home’)…

Also passed the $state param to loginCtrl like :
.controller(‘LoginCtrl’, function($scope, $http, $log, $state)

thanks evryone !

I have a similar issue, I’m using the side menu with a search box, and on return I want to redirect the user the the search controller, however it just doesnt re-route.

 .state('', {
      url: "/search/:term",
      views: {
        'menuContent' :{
          templateUrl: "templates/search.html",
          controller: 'search'

This is my method in the controller. I’ve tried $location.path("/search/" + term); but this doesnt work along with window.location.href = /#/app/search/term

// method in controller
$scope.doSearch = function() {
     $state.go("search",{'term':'San Diego'});

Any help would be awesome.

Stache, try this:

// method in controller
$scope.doSearch = function() {
  $state.go("",{'term':'San Diego'});
1 Like

What the different between $location.path("/home"); and $scope.state.go('home'); ?

Either work, however, it is $state.go, not $scope.state.go.



I have a same problem as above. I am unable to change the state.


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


.state(‘login’, {
url: ‘/login’,
templateUrl: ‘templates/Login.html’,
controller: ‘LoginCtrl’

.state(‘home’, {
url: ‘/home’,
templateUrl: ‘templates/turiamHome.html’,
controller: ‘homeCtrl’




.controller(‘LoginCtrl’, function($scope, LoginService, $ionicPopup, $state) {
$ = {};

$scope.login = function() {
    console.log("LOGIN user: " + $ + " - PW: " + $;

    LoginService.loginUser($, $ {
    	console.log("Login Successful");
    }).error(function(data) {
        var alertPopup = $ionicPopup.alert({
            title: 'Login failed!',
            template: 'Please check your credentials!'


I am able to see the login Success message but the state is not changing.

can you please help.



$location.path is only goes to single and simple page and $state.go is goes to side menu pages and it is very simple task

Are you define your LoginCtrl in your login.html page?? and its not $state.go(‘home’) but its $state.go(‘turiamHome’). i think it works for you