反应路由器上的 onBefore 事件 [英] onBefore event on react-router
问题描述
我可以在 react-router 将我重定向到页面之前调用 Meteor 方法吗?我想记录登录用户的页面浏览量.
Can I call Meteor method before react-router redirect me to a page? I would like to make a history of the logged-in user about his/her page views.
我看到在铁路由器中我可以使用 onBeforeAction: function () {}
I see that in iron-router I can use onBeforeAction: function () {}
我无法为 ReactTraining 的 react-router 找到类似的事件处理程序.我在他们的文档中搜索,https://github.com/ReactTraining/react-router/tree/1.0.x/docs
I cant find similar event handler for react-router of ReactTraining. I am searching in their docs, https://github.com/ReactTraining/react-router/tree/1.0.x/docs
在流星服务器端,我使用的是 simple:json-routes.我还搜索了他们的文档,但找不到与 onBeforeAction 事件处理程序相关的任何内容.
In meteor server side, I am using simple:json-routes. I searched also their docs and can't find anything related to onBeforeAction event handler.
我正在使用 react-router,所以我不能同时使用 Iron-router.那么有没有办法在 Meteor-ReactJS 中记录登录用户的页面浏览量
I am using react-router so I can't use iron-router at the same time. So Is there any way to log the page views of a logged-in user in Meteor-ReactJS
推荐答案
尝试收听浏览器历史记录 browserHistory.listen
Try to listen to the browser history browserHistory.listen
但首先你必须用 getCurrentLocation 检测当前位置
But first you have to detect the current location with getCurrentLocation
这篇关于反应路由器上的 onBefore 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!