如何获得最后/以前访问的路线与铁路由器-流星

How to get last/previous visited route with iron-router - meteor

本文关键字:路由器 流星 最后 何获得 访问      更新时间:2023-09-26

我遇到了一种情况,我需要在meteorjs中使用铁路由器获得最后访问的页面。我查看了他们的文档,但没有得到任何解决方案。它们只有current()函数,它能给你当前的路由名。有办法拿到吗?

我需要它来显示特定的数据时,最后访问的页面等于设置页面。

我试着:

  document.referer 

但这只在页面刷新时起作用。

谢谢,

我不认为你可以直接得到最后一条路线。你可以将当前路由保存在一个Session变量中,并对其进行检查,就像这样(未测试):

Router.route('/route', {
  name: 'route',
  onRun: function() {
    if (Router.current().route === Session.get("lastRoute")) {
      console.log('same route');
    }
  },
  onAfterAction: function() {
    Session.set("lastRoute", Router.current().route);
  },
});

很抱歉回复晚了。我已经成功了。是的,我使用了session。

if (this.route.getName() != currentPageISet) {
      Session.set("showResults", false);
      if (this.route.getName() == prevPage) {
                Session.set("showResults", true);
      }
 }  

谢谢:)