I have defined states using the ui-router like this:
(function() {
'use strict';
angular.module('test.app').config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function($stateProvider, $urlRouterProvider, $locationProvider) {
$stateProvider.state('home', {
url: '/',
templateUrl: 'home/home.html',
controller: 'HomeController',
controllerAs: 'home'
}).state('about', {
url: '/about',
templateUrl: 'about/about.html',
controller: 'AboutController',
controllerAs: 'about'
});
$urlRouterProvider.otherwise('/');
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
}])
.run(['$rootScope', '$templateCache', function($rootScope, $templateCache) {
$rootScope.$on('$stateChangeStart', function(event, next, current) {
if (typeof(current) !== 'undefined'){
$templateCache.remove(current.templateUrl);
}
});
}]);
})();
I have injected ui.router
in my app module.
angular.module('test.app', [..., 'ui.router'...]
home.html:
<div data-ui-view>
<h1>I am home!</h1>
</div>
about.html:
<div data-ui-view>
<h1>I am about!</h1>
</div>
I am using browser-sync
to host it on a local server:
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: "./src"
},
port: 8080
})
});
I am facing a strange problem here. The default route '/'
works perfectly and loads home.html but when i try to access '/about'
I get the message Cannot GET /about
in the browser. There are no errors in the console.
I tried this this and a few more threads but no good! Where did I go wrong?