router.guardRoute is not being called

对着背影说爱祢 提交于 2019-12-11 08:56:20

问题


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?


回答1:


SO here is my answer ;) I have just checked the release form of Durandal 1.2.0 https://github.com/BlueSpire/Durandal/blob/master/Changes.txt And yes the guardRoute is added from this version.

You can check which versions you have in the packages.config file!

The hottowel template you own is probably version 1.1.1 of DurandalJS, this I can see in the NuGet Package Manager. If I want to download the HotTowel template right now it contains DurandalJS 1.1.1

You should update Durandal in the NuGet Manager and also the Durandal Router, then everything should work fine!

I have done this update to (but not from hottowel) and I clicked update ALL, DON'T click this, this will also update/ download Durandal Starterskit and your back at '0'.

Hoped it helps ;)

Greetings from the Netherlands, Leroy



来源:https://stackoverflow.com/questions/16577523/router-guardroute-is-not-being-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!