在实际更改模板之前,Iron Router会钩在路线上 [英] Iron Router hook on a route before actually changing the template

查看:38
本文介绍了在实际更改模板之前,Iron Router会钩在路线上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在用户单击付费对象后立即向其显示付款弹出窗口. 但是在他付款后,他应该直接输入他点击的内容.

i am trying to show the user a payment popup as soon as he clicks on a payed object. But after he pays he should directly enter the content he clicked on.

因此,我认为用路由器解决此问题是一个很好的解决方案,因为我希望页面上重定向到该内容的每个链接都显示此弹出窗口.

Therefore i think its a good solution to solve this with the router, because i want every link on the page that redirects to this content to show this popup.

我的问题是我想在重定向用户之前显示弹出窗口. 所以我尝试了onBeforeAction钩子和东西,但是与铁路由器一起工作的所有东西似乎仅在浏览器的URL更改并且当前模板被卸载后才钩住.

My problem is i want to show the popup before redirecting the user. So i tryed the onBeforeAction hook and stuff but everything working with the iron router seems to only hook in after the URL of the browser changed and the current template was unloaded.

您知道如何获得这种行为吗?

Do you have an idea how to get this kind of behavior?

欢呼

推荐答案

基于此答案,这是您的操作方式可以使用Router.onStop()钩住路由器:

Based on this answer, here is how you can hook the router using Router.onStop():

// onStop hook is executed whenever we LEAVE a route
Router.onStop(function(){
  //check if the current route is the page from where you need to show your 
  //popup and show it based on, for instance, a session variable containing 
  //the previously clicked content id.

});

这篇关于在实际更改模板之前,Iron Router会钩在路线上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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