triggersEnter
is option (not actually a hook), it accepts array of Functions, each function will be called with next arguments:
context
{Route} - Output ofFlowRouter.current()
redirect
{Function} - Use to redirect to another route, same asFlowRouter.go()
methodstop
{Function} - Use to abort current route executiondata
{Mix} - Value returned from.data()
hook- Return: {void}
const scrollToTop = () => {
(window.scroll || window.scrollTo || function (){})(0, 0);
};
FlowRouter.route('/', {
name: 'index',
triggersEnter: [scrollToTop]
});
// Apply to every route:
FlowRouter.triggers.enter([scrollToTop]);
FlowRouter.route('/', {
name: 'index',
triggersEnter: [() => {
console.log('triggersEnter');
}]
});
FlowRouter.route('/', {
name: 'index',
triggersEnter: [(context, redirect) => {
redirect('/other/route');
}]
});
FlowRouter.triggers.enter([cb1, cb2]);