Conditional routing in Durandal

与世无争的帅哥 提交于 2019-12-06 13:41:48

In Durandal 2.0, this is achieved using router.guardRoute:

auth = require('auth');
router.guardRoute = function(model, route) {
    return auth.loggedIn() || '#/login';
};

From what I've read, though undocumented the behavior works the same in Durandal 1.x. Guard route is a function called after the viewModel is loaded but before activate is called on the view model. If true, routing proceeds. If a string, the router tries to navigate to the route associated with that string.

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