triggersExit.md

March 5, 2025 ยท View on GitHub

triggersExit hooks

triggersExit is option (not actually a hook), it accepts array of Functions, each function will be called with one argument:

  • context {Route} - Output of FlowRouter.current()
  • Return: {void}
const trackRouteEntry = (context) => {
  // context is the output of `FlowRouter.current()`
  console.log("visit-to-home", context.queryParams);
};

const trackRouteClose = (context) => {
  console.log("move-from-home", context.queryParams);
};

FlowRouter.route('/home', {
  // calls just before the action
  triggersEnter: [trackRouteEntry],
  action() {
    // do something you like
  },
  // calls when when we decide to move to another route
  // but calls before the next route started
  triggersExit: [trackRouteClose]
});

Global

FlowRouter.triggers.exit([cb1, cb2]);

Further reading