Siva Karthikeyan
Siva Karthikeyan

Reputation: 554

$state.go not redirecting but its loading the content with 200 OK

Here is the plunker link for the code http://plnkr.co/edit/JwM8t3oNepP3tE1nUXlM?p=info

controller.js

if(($scope.login==='Admin')&&($scope.password==='admin'))
{
    $state.go('login.home');
}

script.js

var DailyUsageApp = angular.module('DailyUsageApp', ['ui.router']);
DailyUsageApp.config(function($stateProvider, $locationProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise('/login');
  $stateProvider.state('login', {
      url: '/login',
      templateUrl: "login.html",
      controller: 'authController'
    })
    .state('login.home', {
      url: '/home',
      templateUrl: "home.html",
      controller: 'homeController'
    });
});

Upvotes: 0

Views: 719

Answers (2)

Radim Köhler
Radim Köhler

Reputation: 123861

There is an updated plunker

The most simple solution is to NOT make state login.home nested under login.

//.state('login.home', {
.state('home', {
  url: '/home',
  templateUrl: "home.html",
  controller: 'homeController'
});

There are also other solutions, like create a target for login.home inside of the login like this:

<div ui-view=""></div

But usually, we do not do that. Just login and then navigate to some other state hierarchy...

Upvotes: 1

Matt Way
Matt Way

Reputation: 33141

The reason your code isn't working is because you are creating hierarchical states, that are not meant to be hierarchical. By naming your state login.home, you are saying that home is a child of login. This means that when you try and go('login.home') ui router is attempting to render the login state as well as the home state as a child. This means that for your current layout to work, the login template must contain its own ui-view tag. The best way to fix this is to simply rename your state to just home, and then use $state.go('home');

Upvotes: 4

Related Questions