6

當我嘗試使用兒童路線時,我收到「路線未找到」。爲了涵蓋我的基礎,下面是如何設計應用程序中的路由。Durandal兒童路線未找到路線錯誤

的main.js文件包含路由爲頂級導航和被原樣

    router.map([ 
         { route: 'LOC', moduleId: 'LOC', title: 'LC', nav: 3 } 
        ]); 

我的頁面的頁腳原樣

 router.map('About', 'About', 'About', false); 
    router.map('Help', 'Help', 'Help', false); 

當用戶點擊地圖上的路線進行上面創建的'LOC'路線,左側導航顯示在該視圖上。這種觀點用孩子路由和設置AS-

var childRouter = router.createChildRouter() 
    .makeRelative({ 
     moduleId: 'viewmodels/', 
     fromParent: true 
    }).map([ 
         { route: '*LCClientSearch', moduleId: 'LCClientSearch', title: 'Create LC', type: 'intro', hash: '#LCClientSearch', nav: true }, 
         { route: '*LCPending', moduleId: 'LCPending', title: 'Pending LC', type: 'intro', hash: '#LCPending', nav: true } 

    ]).buildNavigationModel(); 

LOC默認爲LCClientSearch路線,並顯示正確的開始,但是,沒有合適的,從這一點上發生。當用戶點擊LCClientSearh或LCPending時,我得到'路由未找到'的錯誤。

LOC視圖 -

 <div class="span2 well"> 
    <ul class="nav nav-list"> 
     <li class="nav-header">Availability</li> 

     <!--ko foreach: availability--> 
     <li data-bind="css: { active: isActive }"> 
      <a data-bind="attr: { href: hash }, text: title"></a> 
     </li> 
     <!--/ko--> 

     <li class="nav-header">Manual Post</li> 


     <!--ko foreach: ManualPost--> 
     <li data-bind="css: { active: isActive }"> 
      <a data-bind="attr: { href: hash }, text: title"></a> 
     </li> 
     <!--/ko--> 
    </ul> 
</div> 

爲什麼我得到的路線沒有發現?

+0

我認爲你的子路由器中的moduleId應該是'LOC'而不是viewmodels。 – nimgrg

+0

@nimgrg我改變了模塊,但仍然無法正常工作。第一次加載頁面時,它實際上會加載LCClientSearch視圖。所以,它在頁面加載時找到子路由,只是點擊子路由鏈接時導航不起作用。 – Chris

回答

6

我懷疑它是因爲你的父母路線沒有圖示 - check out the documentation for child routers。嘗試從父視圖改變路線:

router.map([ 
    { route: 'LOC*details', moduleId: 'LOC', title: 'LC', nav: 3 } 
]); 

,然後更改子路線:

[ 
    { route: 'LCClientSearch', moduleId: 'LCClientSearch', title: 'Create LC', type: 'intro', nav: true }, 
    { route: 'LCPending', moduleId: 'LCPending', title: 'Pending LC', type: 'intro', nav: true } 
] 

那麼就應該分別LOC/LCClientSearchLOC/LCPending匹配的路由。

+0

謝謝!你懷疑是對的。我不得不添加的另一個附加功能是在父項中使用散列(hash:'#LOC')。 – Chris

+0

真棒,很高興我可以幫助:-) – gerrod

+0

嗨@gerrod,首先感謝您的答案。我已經成功實現了這一點,它像一個魅力工作!但不幸的是,當我嘗試導航到父路由時(例如:LOC),它會在控制檯中向我顯示一條消息,例如:「Route Not Found LOC」。任何幫助或建議將不勝感激。謝謝 ! :) –