我創建了一個Asp.Net MVC並使用nuget添加HotTowel(2013年9月11日的V2.0.1)。我創建了幾個ViewModel,Models。但是,我得到了以下錯誤。無法加載路由模塊requirejs?杜蘭爾蟲?
「無法加載路由模塊(的ViewModels/myVM)詳細說明:用於模塊加載超時:迪朗達爾/插件/路由器\ nhttp://requirejs.org/docs/errors.html#timeout」
是它的問題durandal/plugins/router
?或者它可能是由我添加的一些代碼引起的?
發生在Scripts/durandal/system.js的錯誤。
var logError = function(error) {
if(error instanceof Error){
throw error;
}
throw new Error(error);
};
以下是VM代碼。
define(['services/datacontext', 'durandal/plugins/router', 'services/logger'],
// Remove the durandal/plugins/router and the functions will get rid of the error.
function (datacontext, router, logger) {
var title = 'Event';
var vm = {
activate: activate,
deactivate: deactivate,
refresh: refresh,
events: events,
title: title
};
return vm;
//#region Internal Methods
var events = ko.observableArray();
function activate() {
logger.log(title + ' View Activated', null, title, true);
return datacontext.getEventPartials(events);
}
var deactivate = function() {
events([]);
};
var refresh = function() {
return datacontext.getEventPartials(events, true);
};
//#endregion
});
以下是調用堆棧在router.js
logError [system.js] Line 92 Script
Anonymous function [router.js] Line 359 Script
[External Code]
Anonymous function [system.js] Line 260 Script
[External Code]
[Async Call]
....
代碼,
isProcessing(true);
router.activeInstruction(instruction);
if (canReuseCurrentActivation(instruction)) {
ensureActivation(activator.create(), currentActivation, instruction);
} else {
system.acquire(instruction.config.moduleId).then(function(module) {
var instance = system.resolveObject(module);
ensureActivation(activeItem, instance, instruction);
}).fail(function(err){
system.error('Failed to load routed module (' + instruction.config.moduleId + '). Details: ' + err.message);
});
}
}
和以前一個在system.js。
acquire: function() {
var modules,
first = arguments[0],
arrayRequest = false;
if(system.isArray(first)){
modules = first;
arrayRequest = true;
}else{
modules = slice.call(arguments, 0);
}
return this.defer(function(dfd) {
require(modules, function() {
var args = arguments;
setTimeout(function() {
if(args.length > 1 || arrayRequest){
dfd.resolve(slice.call(args, 0));
}else{
dfd.resolve(args[0]);
}
}, 1);
}, function(err){
dfd.reject(err);
});
}).promise();
},
'require.config.paths'如何看起來像?通常,路由器的路徑是2.0.x中的「plugins/router」。另外,將'var vm = {...'上方'return vm'中定義的所有變量移動,否則在使用前不會定義。 – RainerAtSpirit
main.js中的require.config是'require.config'{path:'text':'../Scripts/text', 'durandal':'../Scripts/durandal', '插件':'../Scripts/durandal/plugins', 'transitions':'../Scripts/durandal/transitions' } });' – ca9163d9
試着用''durandal/plugins/router''替換' '插件/路由器'在VM代碼中。 – RainerAtSpirit