DurandalJS Routing Behavior

浪子不回头ぞ 提交于 2019-12-05 13:55:38

I suspect calling navigateTo where you are might be too soon for some reason. To test this theory try move this code.

    if (dataservice.isAuthenticated() === true) {
        app.setRoot('viewmodels/shell', 'entrance');
        router.navigateTo('home');
    } else {
        app.setRoot('viewmodels/public');
        router.navigateTo('#/public');
    }

into an "activate" method on your publicviewmodel, and in the main.js just leave this:

app.setRoot('viewmodels/public');

EDIT: Old suggestion

I believe on your viewmodel for the root you need a router property. So modify your public viewmodel to add one:

define(['durandal/app', 'durandal/plugins/router', 'services/dataservice'], function (app, router, dataservice) {
   var publicViewModel = function () {
        self.router = router;
        self.logIn = function () {
            app.setRoot('viewmodels/shell');
            router.navigateTo('#/home');
        };

(where do you define self though?)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!