这大概是一个简单的..
我正在尝试覆盖路由器的 guardRoute 功能,似乎我的版本没有被调用。
代码
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;
};
});
});
我没有收到日志消息,路由器继续处理请求。我究竟做错了什么?