我正在尝试在我的 Meteor 应用程序中使用 react-router 实现 alanning Meteor-roles。一切正常,除了我无法正确管理使用alanning角色限制路线或Meteor.user()
我尝试使用流星角色:
我正在尝试onEnter={requireVerified}
在我的路线上使用。这是代码:
const requireVerified = (nextState, replace) => {
if (!Roles.userIsInRole(Meteor.userId(), ['verified'],'user_default')) {
replace({
pathname: '/account/verify',
state: { nextPathname: nextState.location.pathname },
});
}
};
我尝试使用 Meteor.user():
const requireVerified = (nextState, replace) => {
if (!Meteor.user().isverified == true) {
replace({
pathname: '/account/verify',
state: { nextPathname: nextState.location.pathname },
});
}
};
因此,当我单击路线链接时,这是有效的,但是当我手动刷新(F5)时,它不起作用。深入研究后,我发现Meteor.user()
手动刷新页面时还没有准备好。
我知道 Meteor.userid() 或 Meteor.logginIn() 正在工作,但我不仅想验证它们是否被记录,而且它们是否被“验证”或具有作用。
我还尝试使用 react、withcomponentDidMount()
或来检查组件内部componentWillMount()
,在这两种情况下都是相同的,在安装组件之前手动刷新不会加载Meteor.user()
。
那么用meteor/aling角色+反应路由器限制组件/路由的最佳方法是什么?(我在 TheMeteorChef 的基地内使用 react-komposer)
谢谢你。