我正在尝试使用ui-router-extras
. JSON 文件如下所示:
[
{
"name": "app",
"url": "/app",
"abstract": "true",
"resolve": "helper.resolveFor('fastclick', 'modernizr', 'icons')"
},
{
"name": "login",
"url": "/login",
"title": "User Login",
"templateUrl": "",
"redirectToLogin": "true"
},
{
"name": "dashboard",
"url": "/dashboard",
"title": "Dashboard",
"templateUrl": "helper.basepath('dashboard.html')",
"resolve": "helper.resolveFor('flot-chart', 'flot-chart-plugins', 'weather-icons')"
}
]
以下是路由配置文件:
(function () {
'use strict';
angular
.module('app.routes')
.config(routesConfig);
routesConfig.$inject = ['$stateProvider', '$locationProvider', '$urlRouterProvider', 'RouteHelpersProvider', '$stateProvider', '$futureStateProvider'];
function routesConfig($stateProvider, $locationProvider, $urlRouterProvider, helper, $sp, $fsp) {
$locationProvider.html5Mode(false);
var futureStateResolve = function($http) {
return $http.get("states.json").then(function (response) {
console.log(response.data);
angular.forEach(response.data, function (state) {
$sp.state(state);
})
})
}
$fsp.addResolve(futureStateResolve);
// defaults to dashboard
$urlRouterProvider.otherwise('/app/login');
}
})();
状态工作正常,但其他/login
状态不工作并给出错误“invocables must be object”。我认为这是因为函数不起作用helper.basepath()
,helper.resolveFor()
因为它们是来自 JSON 的字符串。
我该怎么办?