我有一个用于帖子索引和显示操作的基本路由器。如果我导航到单个帖子,它会正确呈现页面并将 URL 设置为/#/posts/foo
. 但是,如果我复制 URL 并将其粘贴到新选项卡中,它将加载页面,但 url 将更改为/#/posts/null
. 除了页面被正确呈现并且没有显示错误
show: Em.Route.extend({
route: "/post/:id",
serialize: function(router, context) {
return { id: context.get("id") };
},
deserialize: function(router, context) {
return App.get("store").find(App.Post, context.id);
},
connectOutlets: function(router, context) {
router.get("applicationController").connectOutlet("body", "post", context);
}
})
用一个简单的模型
App.Post = DS.Model.extend({
id: DS.attr("string"),
title: DS.attr("string"),
content: DS.attr("string"),
image: DS.attr("string")
});
日志看起来像这样
STATEMANAGER: Entering root ember.js:17420
STATEMANAGER: Sending event 'navigateAway' to state root. ember.js:17172
STATEMANAGER: Sending event 'unroutePath' to state root. ember.js:17172
STATEMANAGER: Sending event 'routePath' to state root. ember.js:17172
STATEMANAGER: Entering root.show
和一个路由器
App.Store = DS.Store.extend({
revision: 4,
adapter: DS.RESTAdapter.create({
bulkCommit: false
})
});