I am pretty new to Angular and currently building the authentication + navigation part of the app. I followed the ideas described in this useful github entry.
When users navigate to the app they are redirected to <app>/login which displays the login screen properly.
My problem is that in my implementation, unlike the tutorial, when the user sets the URL to <app>/login I am getting 404 instead of the proper page (
<app>/#/login works well).
I am using AngularJS v1.2.5, This is my application config file:
'use strict';
angular.module('myApp', ['ngCookies', 'ngRoute', 'ngResource'])
.config(['$routeProvider', '$locationProvider', '$httpProvider',
function ($routeProvider, $locationProvider, $httpProvider) {
var access = routingConfig.accessLevels;
$routeProvider.when('/',
{
templateUrl: 'views/home.html',
controller: 'HomeCtrl',
access: access.anon
});
$routeProvider.when('/login',
{
templateUrl: 'views/login.html',
controller: 'HomeCtrl',
access: access.anon
});
$routeProvider.when('/404',
{
templateUrl: 'views/404.html',
access: access.anon
});
$routeProvider.otherwise({redirectTo: '/404'});
$locationProvider.html5Mode(true);
$httpProvider.interceptors.push(function ($q, $location) {
return {
'responseError': function (response) {
if (response.status === 401 || response.status === 403) {
$location.path('/login');
return $q.reject(response);
}
else {
return $q.reject(response);
}
}
}
});
}])
.run(['$rootScope', '$location', '$http', 'Auth', function ($rootScope, $location, $http, Auth) {
$rootScope.$on("$routeChangeStart", function (event, next, current) {
$rootScope.error = null;
if (!Auth.authorize(next.access)) {
if(Auth.isLoggedIn()) $location.path('/');
else $location.path('/login');
}
else {
angular.element('body').removeClass('naked');
}
});
}]);
Am I missing something?