我使用react, meteor和flow路由器。如何重定向一旦数据已插入到数据库
这是我的函数
Meteor.call('insertQuestion', header, content,
usernameoremail,date,function(error){
if(error) {
show({text: error.reason, pos: 'bottom-left'});
}
else {
show({text: "Your Question Has been posted", pos: 'top-right'});
}
});
我应该使用哪个流量路由器功能?
FlowRouter。go(pathDef, params, queryParams);
这将通过FlowRouter获得路径。路径,并重新路由到该路径。
可以调用FlowRouter。像这样:
FlowRouter.go("/blog");
你可以在这里查看更多关于flow-router的信息
Meteor.call('insertQuestion', header, content,
usernameoremail,date,function(error){
if(error) {
show({text: error.reason, pos: 'bottom-left'});
}
else {
show({text: "Your Question Has been posted", pos: 'top-right'});
FlowRouter.go(pathDef, params, queryParams)
}
});
使用FlowRouter.go("/path");
重定向用户。您将希望在回调函数中调用它,以便您的代码变为:
Meteor.call('insertQuestion', header, content,
usernameoremail,date,function(error){
if(error) {
show({text: error.reason, pos: 'bottom-left'});
}
else {
show({text: "Your Question Has been posted", pos: 'top-right'});
FlowRouter.go("/somewhere");
}
});