2013-10-09 54 views
0

當我在地址欄輸入定義標準的子路徑:如何在迪朗達爾示例應用程序

http://localhost:28905/#knockout-samples/ 

有左側的Hello世界路線。當我點擊它的地址欄更改爲:http://localhost:28905/#knockout-samples/helloWorld

1)我如何開始與孩子的路線加載http://localhost:28905/#knockout-samples/路線立即所以當我加載淘汰賽樣品我看到

this: http://localhost:28905/#knockout-samples/helloWorld and not 
this: http://localhost:28905/#knockout-samples/ 

從在durandaljs樣本:

var childRouter = router.createChildRouter().makeRelative({ moduleId: 'ko', fromParent: true }).map([ 
      { route: '',    moduleId: 'helloWorld/index',  title: 'Hello World',   type: 'intro' }, 
      { route: 'helloWorld',  moduleId: 'helloWorld/index',  title: 'Hello World',   type: 'intro',  nav: true}, 
      { route: 'clickCounter', moduleId: 'clickCounter/index',  title: 'Click Counter',   type: 'intro',  nav: true}, 
      { route: 'simpleList',  moduleId: 'simpleList/index',  title: 'Simple List',   type: 'intro',  nav: true }, 
      { route: 'betterList',  moduleId: 'betterList/index',  title: 'Better List',   type: 'intro',  nav: true}, 
      { route: 'controlTypes', moduleId: 'controlTypes/index',  title: 'Control Types',   type: 'intro',  nav: true }, 
      { route: 'collections',  moduleId: 'collections/index',  title: 'Collection',   type: 'intro' ,  nav: true }, 
      { route: 'pagedGrid',  moduleId: 'pagedGrid/index',  title: 'Paged Grid',   type: 'intro',  nav: true }, 
      { route: 'animatedTrans', moduleId: 'animatedTrans/index', title: 'Animated Transition', type: 'intro',  nav: true }, 
      { route: 'contactsEditor', moduleId: 'contactsEditor/index', title: 'Contacts Editor',  type: 'detailed', nav: true }, 
      { route: 'gridEditor',  moduleId: 'gridEditor/index',  title: 'Grid Editor',   type: 'detailed', nav: true }, 
      { route: 'shoppingCart', moduleId: 'shoppingCart/index',  title: 'Shopping Cart',   type: 'detailed', nav: true }, 
      { route: 'twitterClient', moduleId: 'twitterClient/index', title: 'Twitter Client',  type: 'detailed', nav: true} 
     ]).buildNavigationModel(); 

回答

1

我用guardRoute做到這一點的頂層如http://dfiddle.github.io/dFiddle-2.0

// Redirecting from/to first route 
    router.guardRoute = function(routeInfo, params, instance){ 
     if (params.fragment === ''){ 
      return routeInfo.router.routes[0].hash; 
     } 
     return true; 
    }; 

https://github.com/dFiddle/dFiddle-2.0/blob/gh-pages/app/shell.js

類似的東西應該是在第二級導航可行的,但我沒有測試過這一點。

+0

謝謝,我看到了小提琴鏈接,並得到了你所完成的真正有用的源代碼。 – Elisabeth