Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm trying to convert my app to use angular-ui-router but I'm unable to get templates/controllers to load. I wanted to have each route defined in each module rather than on the app/index.js file. I have configured the app to default to the login page, which will correctly change the url to /login when an incorrect url is provided. However, the login template and controller are not loaded and when I refresh the page I see Cannot GET /login. I don't see what's wrong with my code:

app/index.js

$locationProvider.html5Mode({
  enabled: true,
  requireBase: false
});

$urlRouterProvider.otherwise('/login');

app/index.html

<!-- content -->
<div id="main" ui-view></div>

app/login/login.routes.js

(function(){
'use strict';

angular.module('loginModule')
.config(function($stateProvider) {
    $stateProvider.state('login', 
    {
        abstract: true,
        url: '/login',
        templateUrl: 'app/login/login.html',
        controller: 'loginController',
        controllerAs: 'vm'
    });
});

})();

app/login/login.controller.js

(function(){
'use strict';

angular.module('loginModule')
.controller('loginController', login);
...

app/login/login.html

<div id="login-content" class="col-md-8" ui-view>
...
share|improve this question
2  
your only state is abstract, and can't be transitioned to. github.com/angular-ui/ui-router/wiki/… – Claies Oct 26 '15 at 23:08
    
Thanks! I was referencing the github.com/johnpapa/angular-styleguide#style-y270 which included this attribute. My template and controller are rendering/loading now but when hit the /login url directly I still see Cannot GET /login. – neridaj Oct 26 '15 at 23:17
1  
    
fixing the abstract attribute only solves the route issues on the client end. As @Phil pointed to, you need to also ensure that the server knows to send those routes to the index.html. The linked article has examples for many different servers. – Claies Oct 26 '15 at 23:23
    
Possible duplicate of AngularJS HTML5 mode reloading the page gives wrong GET request – Phil Oct 26 '15 at 23:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.