1

This is probably a simple one..

I am trying to override the routers guardRoute function and it seems that my version is not being called.

Code

app.start().then(function () {
    router.useConvention();
    viewLocator.useConvention();
    app.setRoot('viewmodels/shell', 'entrance');

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

    router.guardRoute = function (routeInfo, params, instance) {
        logger.logError('guardRoute called', routeInfo, 'main', true);
        return false;
    };
});

Edit 1 - Entire main.js file shown

require.config({
    paths: { "text": "durandal/amd/text" }
});

define(function (require) {
   var system = require('durandal/system'),
        app = require('durandal/app'),
        router = require('durandal/plugins/router'),
        viewLocator = require('durandal/viewLocator'),
        logger = require('services/logger');

    system.debug(true);

    app.title = "my app";

    app.start().then(function () {
        router.useConvention();
        viewLocator.useConvention();
        app.setRoot('viewmodels/shell', 'entrance');

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

        router.guardRoute = function (routeInfo, params, instance) {
            logger.logError('guardRoute called', routeInfo, 'main', true);
            //return false;
        };
    });

});

I do not get my log message and the router continues to process the request. What am I doing wrong?

4

1 に答える 1

1

Durandal 1.2.0 のリリース フォームを確認しましたhttps://github.com/BlueSpire/Durandal/blob/master/Changes.txt そして、このバージョンから GuardRoute が追加されました。

packages.config ファイルで、使用しているバージョンを確認できます。

あなたが所有している hottowel テンプレートはおそらく、DurandalJS のバージョン 1.1.1 です。これは、NuGet Package Manager で確認できます。HotTowel テンプレートを今すぐダウンロードしたい場合は、DurandalJS 1.1.1 が含まれています。

NuGet Manager と Durandal Router で Durandal を更新する必要があります。その後、すべてが正常に動作するはずです。

私はこの更新を (hottowel からではなく) に実行し、[すべて更新] をクリックしました。これをクリックしないでください。これにより、Durandal Starterskit と「0」の背中も更新/ダウンロードされます。

于 2013-05-17T08:25:12.483 に答える