【问题标题】:Oracle Jet router go doesn't do anythingOracle Jet 路由器 go 不执行任何操作
【发布时间】:2016-04-21 16:37:09
【问题描述】:

我正在创建一个包含 4 个路由的应用程序:

登录、主页、page1、page2

当我在登录时检查用户是否已登录,然后它将用户转发到主页。这可以通过获取路由器的 rootinstance 并调用 go 方法完美地工作。

当我在主页检查用户是否未登录时,它必须将用户发送到登录页面。我使用与上面相同的机制,但它没有做任何事情。页面被加载并且用户留在家里。当我添加 router.sync();作为下一个命令,我收到错误,因为同步未定义。有趣的是,发生错误后,路由器确实让我登录。

谁能告诉我发生了什么?

【问题讨论】:

    标签: oracle-jet


    【解决方案1】:

    我曾经遇到过类似的问题,我使用Router.sync 返回的承诺 (router.sync documentation) 解决了这个问题。在.configure 路由器之后在主视图模型中调用Router.sync,然后在promise 的then 函数中调用ko.applyBindings、路由等:

    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);
              }
            );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-15
      • 1970-01-01
      • 2020-07-11
      相关资源
      最近更新 更多