简体   繁体   English

流路由器重定向到数据插入流星js

[英]Flow router Redirect On Data Insert Meteor js

Im using react , meteor and flow router. 我正在使用react,流星和流路由器。 How do I redirect once data has been inserted to the database 数据插入数据库后如何重定向

This is the function I have 这是我的功能

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'}); 
  }
});

Which flow router function should I use? 我应该使用哪种流量路由器功能?

FlowRouter.go(pathDef, params, queryParams); FlowRouter.go(pathDef,params,queryParams);

This will get the path via FlowRouter.path based on the arguments and re-route to that path. 这将基于参数通过FlowRouter.path获取路径,然后重新路由到该路径。

You can call FlowRouter.go like this as well: 您也可以像这样调用FlowRouter.go:

FlowRouter.go("/blog");

You can check more about flow-router here 您可以在此处查看有关流路由器的更多信息

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)
  }
});

Use FlowRouter.go("/path"); 使用FlowRouter.go("/path"); to redirect the user. 重定向用户。 You'll want to call this within the callback function, so that your code becomes: 您需要在回调函数中调用此函数,以便您的代码变为:

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");
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM