未捕获错误:脚本错误:durandal / router

时间:2014-08-12 12:09:27

标签: javascript durandal durandal-2.0

我正在尝试使用durandal路由器,但我的控制台上有这两个错误:

未捕获错误:脚本错误:durandal / router

当然是这样的: 无法加载资源:服务器响应状态为404(未找到)

我知道这是非常自我解释,但我没有在代码或文件结构上发现任何错误。

requirejs.config({
    paths: {
        'text': '../Scripts/text',
        'durandal': '../Scripts/durandal',
        'plugins': '../Scripts/durandal/plugins',
        'transitions': '../Scripts/durandal/transitions'
    }
});

define('jquery', [], function () { return jQuery; });
define('knockout', [], function () { return ko; });


define(['durandal/system', 'durandal/app', 'durandal/viewLocator', 'durandal/plugins/router', 'services/logger'], function (system, app, viewLocator, router, logger) {
    app.title = 'My App';

    //specify which plugins to install and their configuration
    app.configurePlugins({
        router: true,
        dialog: true,
        widget: {
            kinds: ['expander']
        }
    });


    system.debug(true);
    app.start().then(function () {
        router.useConvention();
        viewLocator.useConvention();

        app.setRoot('viewmodels/shell');

        router.handleInvalidRoute = function (route, params) {
            logger.logError('No route found', route, 'main', true);
        };
    });
});

shell.js

define(['durandal/system', 'services/logger', 'durandal/plugins/router','config'],
    function(system,logger, router, config) {
        var shell ={
            activate: activate,
            router: router
        };

        return shell;

        function activate(){
            logger.log('CodeCamper Jumpstart Loaded!',
                null,
                system.getModuleId(shell),
                true)
            router.map(config.routes);
            return router.activate(config.startModule);
        }
    }
);

vs结构

http://screencast.com/t/Occ6BICg

1 个答案:

答案 0 :(得分:1)

尝试仅使用插件路径声明来询问路由器。

define(['durandal/system', 'durandal/app', 'durandal/viewLocator', 'plugins/router', 'services/logger'], function (system, app, viewLocator, router, logger) {

   //Your code here

});

我猜这种情况正在发生,因为在你的要求中你有durandal和插件都附加到路由器。由于它们都在路径配置中,因此导致解析的路径不正确。