如何导航回搜索页面?

How navigate back to search page?

Meteor/Iron路由器访问单次查看结果后跳转回搜索页面的方法是什么?我目前正在使用 history.back(),但它有时会出错。它不适用于直接登陆单一视图页面的访问者。我正在试用 Session,但我不确定使用哪些参数是好的做法。或者也许还有另一种方法?谢谢! ~启

实际上 iron:router 有一个方法叫做 Location.back()

看起来 history.back() 也是一个不错的选择。

勾选这个Add 'previousPage' and 'backMethods' or this feature request

如果您只想在 search template 上执行此操作,请尝试使用此代码。

// onStop offshoot is executed whenever we LEAVE a lane
Router.onStop(function(){
  // register the previous route into a Session
  Session.set("previousLocation",this.location.path);
});

// onBeforeAction is executed before indeed going to a new lane
Router.onBeforeAction(function(){
  // getting the previous route
  var previousLocationPath=Session.get("previousLocation");
  // now lets back to search route.
  if(previousLocation ==="/search"){
    this.redirect("search");
  }
  this.next();
});

从这个 Previous Page location on ironRouter 教程中获取此代码