簡體   English   中英

流路由器重定向到數據插入流星js

[英]Flow router Redirect On Data Insert Meteor js

我正在使用react,流星和流路由器。 數據插入數據庫后如何重定向

這是我的功能

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.path獲取路徑,然后重新路由到該路徑。

您也可以像這樣調用FlowRouter.go:

FlowRouter.go("/blog");

您可以在此處查看有關流路由器的更多信息

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM