当我在模板的帮助程序中返回非静态的东西时,Meteor 会抛出错误“Deps 重新计算异常:用户名”。
Router.configure({
layoutTemplate: 'layout'
});
Router.map(function() {
this.route('home', {path: '/'});
this.route('dashboard');
})
if (Meteor.isClient) {
Accounts.ui.config({
passwordSignupFields: 'USERNAME_AND_EMAIL'
});
Template.dashboard.helpers({
username: function() {
return Meteor.user().username;
}
});
}
<template name="layout">
<h1>Layout</h1>
{{yield}}
</template>
<template name="home">
{{#link route='dashboard'}}Dashboard{{/link}}
</template>
<template name="dashboard">
{{#link route='home'}}Home{{/link}}
{{username}}
</template>
奇怪的是,当通过单击主页模板中的链接访问仪表板路线时,一切正常。但是当我在 url 栏中输入 /dashboard 时,我得到了那个错误。