IronRouter上一页的位置 [英] Previous page location on IronRouter

查看:51
本文介绍了IronRouter上一页的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IronRouter中进入下一页之前,是否可以获取上一页的位置?

Is there a way to get the previous page location before going to the next page in IronRouter?

是否有可以用来获取此信息的事件?

Is there an event I can use to fetch this information?

谢谢.

推荐答案

您可以通过使用钩子来实现所需的行为.

You can achieve the behavior you want by using hooks.

// onStop hook is executed whenever we LEAVE a route
Router.onStop(function(){
  // register the previous route location in a session variable
  Session.set("previousLocationPath",this.location.path);
});

// onBeforeAction is executed before actually going to a new route
Router.onBeforeAction(function(){
  // fetch the previous route
  var previousLocationPath=Session.get("previousLocationPath");
  // if we're coming from the home route, redirect to contact
  // this is silly, just an example
  if(previousLocationPath=="/"){
    this.redirect("contact");
  }
  // else continue to the regular route we were heading to
  this.next();
});

这是使用iron:router@1.0.0-pre1

这篇关于IronRouter上一页的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆