2016-04-21 17 views
0

我創建一個應用程序,它由4路,那麼它會將用戶轉發到家。這可以通過獲取路由器的rootinstance和call go方法來完美工作。甲骨文噴氣路由器去什麼都不做

當我檢查用戶是否未在主頁上登錄時,它必須將用戶發送到登錄頁面。我使用與上面所做的相同的機制,但它沒有做任何事情。頁面加載並且用戶停留在家中。當我添加router.sync();作爲下一個命令,我得到錯誤,因爲同步是未定義的。有趣的是,錯誤發生後,路由器確實寄給我登錄。

誰能告訴我發生了什麼?

回答

0

我曾經有類似的問題,我使用Router.sync返回的承諾解決了(router.sync documentation)。呼叫Router.sync在主視圖模型您.configure路由器後,再打電話給你ko.applyBindings,路由等在承諾的then功能是這樣的:

oj.Router.rootInstance.configure(...); 
oj.Router.sync().then(
      function() { 
      // bind your ViewModel for the content of the whole page body. 
      ko.applyBindings(
       new RootViewModel(), 
       document.getElementById('globalBody') 
      ); 
      // navigate the user to login or wherever you want them to be now 
      oj.Router.rootInstance.go('login'); 
      }, 
      function (error) { 
      oj.Logger.error('Error in root start: ' + error.message); 
      } 
     );