Skip to content

Latest commit

 

History

History
54 lines (46 loc) · 1.53 KB

triggersEnter.md

File metadata and controls

54 lines (46 loc) · 1.53 KB

triggersEnter

triggersEnter is option (not actually a hook), it accepts array of Functions, each function will be called with next arguments:

  • context {Route} - Output of FlowRouter.current()
  • redirect {Function} - Use to redirect to another route, same as FlowRouter.go() method
  • stop {Function} - Use to abort current route execution
  • data {Mix} - Value returned from .data() hook
  • Return: {void}

Scroll to top:

const scrollToTop = () => {
  (window.scroll || window.scrollTo || function (){})(0, 0);
};

FlowRouter.route('/', {
  name: 'index',
  triggersEnter: [scrollToTop]
});

// Apply to every route:
FlowRouter.triggers.enter([scrollToTop]);

Logging:

FlowRouter.route('/', {
  name: 'index',
  triggersEnter: [() => {
    console.log('triggersEnter');
  }]
});

Redirect:

FlowRouter.route('/', {
  name: 'index',
  triggersEnter: [(context, redirect) => {
    redirect('/other/route');
  }]
});

Global

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

Further reading