【发布时间】:2013-11-14 07:27:03
【问题描述】:
我整天都在苦苦挣扎,无法弄清楚如何在我的基于热毛巾 (MVC4 SPA) 的项目中使用 Durandal 正确创建子路由器。这是我目前拥有的:
shell.js
var routes = [
{ route: '', moduleId: 'home', title: 'Home', nav: 1 },
{ route: 'inventory/index', moduleId: 'inventory/inventory', title: 'Inventory', nav: 2 }];
return router.makeRelative({ moduleId: 'viewmodels' }) // router will look here for viewmodels by convention
.map(routes) // Map the routes
.buildNavigationModel() // Finds all nav routes and readies them
.activate(); // Activate the router
inventory.js
define(['services/logger', 'plugins/router'], function (logger, router) {
var title = 'Details';
var childRouter = router.createChildRouter()
.makeRelative({
moduleId: 'viewmodels/inventory',
fromParent: true
}).map([
{ route: '', moduleId: 'inventory', title: 'Inventory', nav: 3 },
{ route: 'items', moduleId: 'items', title: 'Items', nav: 4 }])
.buildNavigationModel();
var vm = {
router: childRouter,
activate: activate,
title: title
};
return vm;
//#region Internal Methods
function activate() {
logger.log(title + ' View Activated', null, title, true);
}
//#endregion
});
我目前遇到的问题:
- 当我点击库存视图时,它会被激活两次
- 没有其他导航选项可见,尽管右上角出现了一些空的 3D 圆角矩形...我不确定这是无法消失的进度条还是某些失败的导航元素。
我的项目文件是这样组织的:
【问题讨论】:
-
检查在 shell.js 中将显式路由
inventory/index更改为 splat 路由inventory/index/*whatever是否有所不同。见durandaljs.com/documentation/Using-The-Router -
@RainerAtSpirit 它消除了对详细信息视图的额外激活,但控制台日志随后报告“LOG: Route '*whatever' Not Found”(我将错误报告代码更改为
system.log('Route \'' + coreFragment + '\' Not Found');所以我有一些线索是怎么回事)。 -
仅供参考,3d 矩形是您删除字体真棒但不显示外壳导航更改的微调器对象的地方
标签: javascript asp.net-mvc-4 durandal hottowel