是不是可以在history.push('...')之前发送一个事件?
是的,这完全没问题。你所要做的就是地图 VIEW_BLOG_POST 到一个新的事件定义。该动作不必以任何方式改变状态。它将通过reducers,它们将返回对先前状态的引用。如果您使用的是react-redux,则对性能的影响几乎为零。假设您将此作为GA中的事件进行跟踪,它看起来像这样:
VIEW_BLOG_POST
import { trackEvent } from '@redux-beacon/google-analytics'; const trackBlogPostClick = trackEvent((action, prevState, nextState) => { return { category: /* fill me in */, action: /* fill me in */, label: /* (optional) */, value: /* (optional) */, }; }, /* (optional) tracker names array or tracker name string */ ); // And wherever your events map is: const eventsMap = { VIEW_BLOG_POST: trackBlogPostClick, }
没有真正改变状态,只是为了用redux-beacon中间件来捕捉事件?