流星 - loading/refreshing 页面时出错:Tracker afterFlush 函数异常:未定义

Meteor - Error when loading/refreshing page: Exception from Tracker afterFlush function: undefined

如上所述,我遇到了一个错误并显示了一个空白页面(但包括导航栏在内的布局)。当我通过浏览器刷新 link 或直接通过浏览器访问 link 时,总是会出现此错误。当我使用导航栏浏览模板时,一切都很好。因此,在页面的真实 "load" 之后我看不到任何数据。

我正在 Windows 上使用 Meteor Blaze。

截图如下:

图片和其他数据均未显示。

我不确定,这是否是该行为的 100% 原因,但如果发生此行为,我总是会在客户端控制台中收到此错误消息:

Exception from Tracker afterFlush function: undefined

TypeError: Cannot read property 'username' of undefined at Blaze.TemplateInstance. (http://localhost:3000/app/client/templates/common/navigation.js?hash=142e989d312ba94a4b875a71e5e557bdd5255272:3:40) at http://localhost:3000/packages/blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3398:22 at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744:12) at fireCallbacks (http://localhost:3000/packages/blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3394:12) at Blaze.View. (http://localhost:3000/packages/blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3487:5) at http://localhost:3000/packages/blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1845:14 at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271:12) at http://localhost:3000/packages/blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1844:15 at Object.Tracker._runFlush (http://localhost:3000/packages/tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:548:11) at onGlobalMessage (http://localhost:3000/packages/meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:398:23) undefined

我搜索了 tracker、afterFlush 等,但我不确定我的代码必须更改什么?

当您加载此路由时 "fresh"(使用刷新或将 url 粘贴到浏览器中)Meteor 会重新加载整个应用程序 ,包括 Meteor.user() 对象。在 client/templates/common/navigation.js 的第 40 行,您可能正在尝试访问 Meteor.user().username,但 Meteor.user() 尚未加载,因此出现错误。您需要在您的代码中对此进行防御 and/or 显示一个加载模板,直到您的订阅和用户对象都准备就绪。

错误转储的第一行指向错误:

TypeError: Cannot read property 'username' of undefined at Blaze.TemplateInstance.
(http://localhost:3000/app/client/templates/common/navigation.js?hash=142e989d312ba94a4b875a71e5e557bdd5255272:3:40)

末尾的:40是发生错误的行号