当用户手动更改URL时,EmberJS转换错误路由未定义

时间:2016-03-01 19:41:38

标签: ember.js

我一直试图调试这个问题一段时间,似乎无法找出我的应用程序崩溃的原因。 我有以下路由器:

Router.map(function() {
  this.route('post', {path: 'post/:id'});
});

和相应的路线:

export default Ember.Route.extend({
  model(params) {
    return this.store.findRecord('post', params.id);    
  },
});

如果用户转到localhost:4200/post/1,一切都很好。但是,如果用户手动将路由更改为localhost:4200/post/2,则会获得以下堆栈跟踪:

TypeError: Cannot set property 'endTime' of undefined
    at TransitionData.routeFinishedSetup (transition-data.js:50)
    at routeWillRender (ember-perf.js:124)
    at renderTemplate (route.js:14)
    at superWrapper [as renderTemplate] (ember.debug.js:21573)
    at _emberRuntimeSystemObject.default.extend.setup (ember.debug.js:26400)
    at Object.callHook (ember.debug.js:50998)
    at handlerEnteredOrUpdated (ember.debug.js:49778)
    at setupContexts (ember.debug.js:49742)
    at finalizeTransition (ember.debug.js:49924)
    at ember.debug.js:49359

我尝试查看routeFinishedSetup中的代码,似乎this.routes是一个空数组。

通过一些调试,我发现如果我更改模型功能使得它不会调用商店,则不会再发生此错误。例如,如果我在这里实现自定义承诺,它可以正常工作。 如何进一步调试此问题或者是否有人可以提出解决方案?谢谢!

编辑:

因此,在用户手动更改URL后,正确检索新模型,但代码在路径渲染步骤中断?

1 个答案:

答案 0 :(得分:0)

This might sound like it has nothing to do with your problem.
But if it isn't already change the locationType attribute in environment.js to 'hash'.
Also is that your complete route.js? Because the error seems to be occurring at route.js:14. Try to provide a fiddle or twiddle.