我不想懒加载我的路线模板.相反,我想在执行任何路由之前将所有路由模板加载到$templateCache中.
@H_502_10@这就是我在做的事情:
angular.module('myApp',['ngRoute']).config(['$routeProvider','$locationProvider',function ($routeProvider,$locationProvider) { $locationProvider.html5Mode(false); $routeProvider.when("/main",{templateUrl: "main",controller: "MainCtrl"}) .when("/login",{templateUrl: "login",controller: "LoginCtrl"}); }]) .run(['$location','$templateCache',function ($location,$templateCache) { //...Save templates in $templateCache $location.path("/login"); }]);
如果您浏览到/,因为它与任何路由都不匹配,这可以正常工作.但是如果你浏览或刷新/#/ login,似乎路由服务试图在我的运行块运行之前加载模板并向服务器发出请求.
无论如何要确保填充$templateCache的代码将在路由服务寻找模板之前执行?