angular .module('app', ['ng', 'ngRoute', 'appView']) .config(function ($httpProvider, $routeProvider, $locationProvider) { $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; $routeProvider .when('/', { controller: 'IndexController', templateUrl: 'app/views/index/index.tpl.html' }) .when('/list', { controller: 'ListController', templateUrl: 'app/views/list/list.tpl.html' }); $routeProvider.otherwise({ redirectTo: '/' }); // 未找到指定的路由地址,重定向到home页 $locationProvider.html5Mode({ enabled: true, requireBase: false }); }) .run(function ($rootScope, $location) { /* 监听路由的状态变化 */ $rootScope.$on('$routeChangeStart', function (event, next, current) { console.log('route begin change'); }); $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { console.log('route have already changed :' + $location.path()); }); }) .controller('AppController', function () { console.log('Application Loaded!'); });