Routing.navigate vs document.location.hash
Routing.navigate vs document.location.hash
我用backbone.marionette
构建了一个网络应用程序。当我从Marionette.ItemView
触发事件时document.location.hash
:
document.location.hash = '#tasks/' + this.model.get('id');
1.a) 它改变了网址1.b) 它触发了应用路由
如果我从同一位置触发Routing.navigate
:
router.navigate('#tasks/' + this.model.get('id'))
2.a) 它按预期更改了网址2.b) 它不会触发应用路由。
知道为什么会发生 2.b 吗?问题可能出在哪里?
谢谢。
var Router = Marionette.AppRouter.extend({
appRoutes: {
'tasks': 'tasks',
'tasks/:id': 'taskDetail',
'*defaults': 'tasks'
}
});
您需要
添加{trigger: true}
router.navigate('#tasks/' + this.model.get('id'), {trigger: true})
通常,我扩展路由器,然后添加自己的导航,自动添加该{trigger: true}
。我理解为什么开发人员这样做,但这不是我使用它的方式:)
相关文章:
- IE中不支持JQuery window.location.hash
- 历史推送状态不在独立的 location.hash 或 location.href 中,而是在 Location 对象本
- window.location.hash = “”;强制在Chrome和Safari上重新加载框架集
- location.hash总是空的
- 正在尝试将变量传递到window.location.hash
- 从(window.location.hash)中删除哈希
- 根据location.hash传递的数据重新呈现ReactJS嵌套的子组件
- AngularJS location.hash animation
- window.location.hash始终显示为空
- Routing.navigate vs document.location.hash
- window.location.hash,IE,Back and Forward:地址栏中的值更改,但不在DOM中更改
- 在 window.location.hash 中使用斜杠
- 在 Location.hash 上从 URL 中删除 #
- 在移动设备上使用 window.location.hash 和锚标记
- jQuery + window.location.hash 和同页锚点 - 不一致的行为
- 从Chrome 47开始,设置window.location.hash不适用于后退按钮
- “window.location.href”和“window.location.hash”有什么区别
- Firefox 中的 window.location.hash 问题
- 如何使用(location.hash)和(.trigger)进行导航
- Chrome:设置window.location.hash会导致“在页面中查找”搜索框消失