我正在做一个带有backbone和backbone-layout-manager的构建。当我需要进行视图更改时,我需要将页面更新为新标题。我尝试添加了一个名为setTitle的方便方法,
setTitle: (new_title) ->
document.title = new_title
console.log "changed title to: #{new_title}"在路由改变时,我可以在我的路由器中调用。这很好用,但是,有一个问题。当我检查我的浏览器历史记录时,很明显它显示了与前一个页面相关联的标题。示例(按访问页面的顺序排列为1-3):
1. localhost/#/home/ - "Website"
2. localhost/#/blog/ - "Website - Home"
3. localhost/#/home/ - "Website - Blog"我看到路由器直到url发生变化并且我的浏览器Chrome将该页面添加到其历史记录之后才会调用该路由。
我的问题是,我如何更新页面的标题,以便在我的浏览器历史记录中主动反映该标题。
更新:这不是Safari的问题,IE有点像是做自己的事情。
发布于 2015-07-29 00:50:03
我能够简单地通过更新每个路由回调中的document.title来实现这一点。
Backbone.Router.extend({
routes: {
'posts': 'posts',
'posts/new': 'newPost'
},
posts: function() {
document.title = 'All Posts';
// do something
},
newPost: function() {
document.title = 'New Post';
// do something
}
})https://stackoverflow.com/questions/15914385
复制相似问题