我刚刚将我的项目升级为durandaljs 2.0。 从某种意义上说,如果我在浏览器地址栏中输入路径网址并点击输入,那么一切似乎都工作得很好,它可以很好地加载哈希路径的视图。这适用于我的所有路线。
但是,如果我点击href中具有完全相同哈希路径的导航栏按钮,浏览器网址将更改为正确的网址(如果我在地址栏中按Enter键,则该网址会有效),但视图不会负荷。
它几乎就像一个没有触发器的router.navigate被调用。
我实际上手动尝试调用route.navigate(“#xyz”,{replace:false,trigger:true}),但这也没有加载xyz视图。
我在这里忽略了一些愚蠢的东西 - 任何想法?
来自shell.js的:
activate: function () {
$.getJSON("/Account/GetCurrentUser").done(function (data, textStatus, jqXHR) {
shell.user(data);
});
$(document).ajaxError(function (xhr, props) {
if (props.status === 401) {
window.location = "/Account/Login";
}
});
router.map([
{ route: '', title: 'Jobs', moduleId: 'viewmodels/jobs', nav: true },
{ route: 'companies', title: 'Companies', moduleId: 'viewmodels/companies', nav: true },
{ route: 'profile', title: 'Profile', moduleId: 'viewmodels/profile', nav: true },
{ route: 'users', title: 'Users', moduleId: 'viewmodels/users', nav: true, hash: '#users' },
{ route: 'jobs(/filter/:filter)(/group/:group)(/sort/:sort)(/page/:page)', title: 'Jobs', moduleId: 'viewmodels/jobs', nav: false },
{ route: 'companies(/filter/:filter)(/group/:group)(/sort/:sort)(/page/:page)', title: 'Companies', moduleId: 'viewmodels/companies', nav: false }
//,{ route: 'flickr', moduleId: 'viewmodels/flickr', nav: true }
]).buildNavigationModel();
//router.mapNav('details');
//router.mapNav('airports');
//router.mapNav('emptylegs');
return router.activate();
}
来自nav.html的:
<nav class="navbar navbar-fixed-top" style="max-height:68px">
<div class="navbar-inner">
<a class="brand" href="/">
<span class="title"></span>
</a>
<div>
<ul class="nav" data-bind="foreach: router.navigationModel">
<li><a data-bind="css: { active: isActive }, attr: { href: hash }, text: title"
class="btn btn-info" href="#"></a>
</li>
</ul>
</div>
</div>
</nav>
由于
答案 0 :(得分:1)
我不知道这是不是问题,但在a
绑定中,您正在使用knockout更改href,然后再次设置href="#"
。
<a data-bind="css: { active: isActive }, attr: { href: hash }, text: title"
class="btn btn-info" href="#"></a>
可能不是问题的原因。但这看起来并不好......
顺便说一句,还要检查与路由器的绑定是否正确完成。在Durandal 2.0中它发生了变化,所以在你的shell.html
中你应该有这样的东西:
<!--ko router: { transition:'entrance', cacheViews:true }--><!--/ko-->
而不是:
<!--ko compose: {
model: router.activeItem,
afterCompose: router.afterCompose,
transition: 'entrance'
} -->