【问题标题】:How navigate back to search page?如何导航回搜索页面?
【发布时间】:2015-02-19 12:41:52
【问题描述】:

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

【问题讨论】:

    标签: javascript session meteor navigation iron-router


    【解决方案1】:

    其实iron:router有个方法叫Location.back()

    history.back() 似乎也是一个不错的选择。

    检查此Add 'previousPage' and 'backMethods'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 教程中获取此代码

    【讨论】:

    • 感谢@Ethaan!这非常有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    • 2020-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多