[英]Meteor : redirect if user didn't create page
在Meteor中,我有一個產品編輯頁面。 我只希望創建產品的用戶看到該頁面。 否則,您將被重定向。
有沒有辦法僅通過鐵路由器來實現此重定向? 如果沒有,我將采取任何解決方案。
router.js
var OnBeforeActions;
OnBeforeActions = {
ownerRequired: function(pause){
if(!Meteor.userId()){
Router.go('home');
}else if(Meteor.userId()._id != ....SOMETHING?....){
Router.go('home');
}else{
this.next();
}
}
};
Router.onBeforeAction(OnBeforeActions.ownerRequired, {
only: ['editProduct']
});
Router.route('/editProduct/:_id',{
template: "editProduct",
name: "editProduct",
data: function(){
return Products.findOne({_id: this.params._id});
}
});
因此,如果您想知道如何在沒有鐵路由器的情況下解決此問題。 你可以做這樣的事情。 (請注意,如果用戶已登錄,我已經使用onBeforeAction進行了檢查。)
Template.editProduct.onCreated(function(){
if(this.data.user === Meteor.userId()){
}else{
Router.go('home');
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.