没有调用router.guardRoute [英] router.guardRoute is not being called

查看:131
本文介绍了没有调用router.guardRoute的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个简单的..

This is probably a simple one..

我正在尝试覆盖路由器的guardRoute功能,并且似乎没有调用我的版本.

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

代码

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;
    };
});

编辑1-显示整个main.js文件

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?

推荐答案

所以这是我的答案;) 我刚刚检查了Durandal 1.2.0的发布形式 https://github.com/BlueSpire/Durandal/blob/master/Changes.txt 是的,guardRoute是从该版本添加的.

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.

您可以检查packages.config文件中具有哪些版本!

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

您拥有的hottowel模板可能是DurandalJS的1.1.1版本,我可以在NuGet软件包管理器中看到.如果我现在想下载HotTowel模板,它包含DurandalJS 1.1.1

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

您应该在NuGet Manager和Durandal Router中更新Durandal,然后一切正常!

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

我已将此更新更新为(但不是从hottowel进行的)更新,我单击了更新全部",不要单击此更新,这还将更新/下载Durandal Starterskit,并且您的背面为"0".

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'.

希望它会有所帮助;)

来自荷兰勒罗伊的问候

这篇关于没有调用router.guardRoute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆