GET*_*Tah 9 javascript knockout.js durandal
我正在查看Durandal样本,试图了解路由的工作原理.
shell.js指定了这些路由:
{ route: ['', 'knockout-samples*details'], moduleId: 'ko/index', title: 'Details...', nav: true, hash: '#knockout-samples' },
{ route: 'view-composition',moduleId: 'viewComposition/index', title: ...
Run Code Online (Sandbox Code Playgroud)
在knockout-samples:
{ route: '', moduleId: 'helloWorld/index', title: 'Hello World', type: 'intro' },
{ route: 'helloWorld', moduleId: 'helloWorld/index', title: 'Hello World', type: intro', nav: true},
Run Code Online (Sandbox Code Playgroud)
我想要实现的是拥有另一个层次结构helloWorld.像这样的东西:

我试过这个但没有运气:
{ route: '', moduleId: 'helloWorld/index', title: 'Hello World', type: 'intro' },
{ route: 'helloWorld*details', moduleId: 'helloWorld/index', title: 'Hello World', type: 'intro', nav: true, hash:'#knockout-samples/helloWorld'}
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.
Durandal路由不支持此级别的导航吗?
在创建"孙子"或"曾孙子"或更深的子路由器时,诀窍是引用相对父路由器,而不是根路由器.要获取对父路由器的引用,请将包含父路由器的模块添加为"孙子"模块的依赖项.你可以无限期地嵌套这样的路由器.例如:
myModuleWithChildRouter.js
define(['plugins/router'], //reference to durandal root router
function(router) {
var _childRouter = router.createChildRouter();
return { myNewChildRouter: _childRouter}
}
Run Code Online (Sandbox Code Playgroud)
myModuleWithGrandchildRouter.js
define(['myModuleWithChildRouter'], //reference to module with child router
function(childRouterModule) {
var _grandChildRouter = childRouterModule.myNewChildRouter.createChildRouter();
.....
}
Run Code Online (Sandbox Code Playgroud)
希望有所帮助!
如果您使用 durandal 2.0,您可以设置子路由器。这将允许您在 hello world 下创建一个新路由器,您可以为视图中的子视图链接附加信息。您可以在文档中查找这些内容,但请确保在视图中设置该路由器,以便当您点击类似的路线时
#helloworld/subview
Run Code Online (Sandbox Code Playgroud)
你已经激活了helloworld
| 归档时间: |
|
| 查看次数: |
4438 次 |
| 最近记录: |