【问题标题】:Uncaught Error: Script error for: durandal/router未捕获的错误:脚本错误:durandal/router
【发布时间】:2014-08-12 20:46:31
【问题描述】:

我正在尝试使用 durandal 路由器,但我的控制台上出现以下 2 个错误:

未捕获的错误:脚本错误: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

【问题讨论】:

标签: javascript durandal durandal-2.0


【解决方案1】:

尝试仅使用插件路径声明请求路由器。

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

   //Your code here

});

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

【讨论】:

  • 我在原始问题中添加了 shell.js,如果我从定义中删除 /durandal,则会出现更严重的错误。 Uncaught TypeError: undefined is not a function (显然在 viewlocator 行)
  • 你能检查一下这个问题,看看它对你有什么帮助吗stackoverflow.com/questions/16677596/durandal-routing-issue我对 durandal 不太了解......
猜你喜欢
  • 2017-03-30
  • 2019-07-26
  • 2019-07-16
  • 1970-01-01
  • 1970-01-01
  • 2016-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多