我Uncaught TypeError: pathDef.replace is not a function
在 MeteorJS 中使用 Flow Router 时遇到控制台错误。我是 Flow 的新手,之前使用过 Iron Router,所以可能没有正确地做某事。
请注意,如果我先加载另一个页面然后导航到此页面,它可以正常工作,但如果我重新加载页面,我会收到错误消息。
下面是错误代码:
客户端模板
{{#if Template.subscriptionsReady}}
{{#each users}}
<tr>
<td>
{{linkNames profile.firstname profile.lastname}}
</td>
<td>
{{username}}
</td>
<td>
{{emails.[0].address}}
</td>
<td>
{{toUpperCase roles.[0]}}
</td>
<td>
{{getUsernameById createdBy}}
</td>
<td>
<a href="#" class="text-primary admin-edit-user" data-toggle="modal" data-target="#editUser" id="{{_id}}"><i class="fa fa-edit"></i></a>
</td>
<td>
<a href="#" class="text-danger admin-delete-user" id="delete{{_id}}"><i class="fa fa-times"></i></a>
</td>
</tr>
{{else}}
<tr>
<td colspan="6">
<p>There are no users</p>
</td>
</tr>
{{/each}}
{{else}}
<p>Loading...</p>
{{/if}}
酒馆
/* Users */
Meteor.publish('users', function() {
if (Roles.userIsInRole(this.userId, ['admin', 'team'])) {
return Meteor.users.find({}, {
fields: {
'profile.firstname': 1,
'profile.lastname': 1,
'emails': 1,
'username': 1,
'roles': 1,
'createdBy': 1
},
sort: {'roles': 1}
})
} else if (Roles.userIsInRole(this.userId, ['client'])) {
return Meteor.users.find({}, {
fields: {
'profile.firstname': 1,
'profile.lastname': 1,
'emails': 1,
'username': 1
}
});
}
});
客户端JS
/* On created */
Template.users.onCreated(function() {
var instance = this;
instance.autorun(function() {
instance.users = function() {
instance.subscribe(Meteor.users.find({}));
}
});
});
/* Helpers */
Template.users.helpers({
users: function() {
var users = Meteor.users.find({});
return users;
}
});
Exception in template helper: TypeError: Cannot read property 'username' of undefined
我还在以下全局帮助程序的其他模板中遇到错误(尽管帮助程序按预期工作):
/* Current Username */
Template.registerHelper('currentUsername', function() {
return Meteor.user().username;
});