简体   繁体   English

Flowrouter-必须重新加载整个页面才能识别路线

[英]Flowrouter - have to reload whole page for route to be recognised

Quite basic setup - user submits a post, it's inserted by a method, then user should be routed to a confirm page with the _id of the newly created post: 相当基本的设置-用户提交帖子,通过方法将其插入,然后应将用户转到带有新创建帖子的_id的确认页面:

const onSubmitPost = (post) => {
      createPost.call(post, (err, res) => {
        if(err) {
          instance.errorMessage.set(err.reason);
        } else {
          FlowRouter.go("create-post/:postId/confirm", { postId: res });
      }
   });
};

// Route definition    
FlowRouter.route("/create-post/:postId/confirm", {
  name: "create-confirm",
  action() {
    BlazeLayout.render("MainPage", { content: "ConfirmPostContainer" });
  }
});

But when I try this, I get There is no route for the path: create-post/abc123/confirm 但是当我尝试这样做时,我得到There is no route for the path: create-post/abc123/confirm

If I manually press reload, it works fine - no problems. 如果我手动按重新加载,则效果很好-没问题。

Anyone have any idea what's going on, and how to fix? 任何人都知道发生了什么,以及如何解决?

EDITS 编辑

  • This is called on the /create-post route - redirect to confirm the post after it's created 这是在/create-post路由上调用的-在/create-post重定向以确认该帖子
  • Added route definition 添加路线定义
  • Tried using redirect instead of go - no difference 尝试使用redirect而不是go -没什么区别

There are 2 things I can suggest you to try. 我可以建议您尝试2件事情。 My hunch is that the problem stems from calling the .go method from /create-post with a relative path. 我的直觉是,问题源于使用相对路径从/create-post调用.go方法。

So, first, try route-names instead: FlowRouter.go('create-confirm', { postId: res }); 因此,首先尝试使用路由名称: FlowRouter.go('create-confirm', { postId: res });

Second, try absolute paths: FlowRouter.go('/create-post/' + res + '/confirm'); 其次,尝试绝对路径: FlowRouter.go('/create-post/' + res + '/confirm'); - notice the leading slash / ! -注意前导斜杠/

Does that work? 那样有用吗?

尝试FlowRouter.redirect(您的路线名称,{postId:res}

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

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