Router.Hooks

Router.Hooks

Source:

Route Hook Methods - The Router.Hooks namespace provides a router-agnostic API for registering functions to be called either on specific routes or on every route. Read more about Routing in Reaction.

Methods

(static) get(type, name) → {Array}

Get all registered hooks for a specific route

Source:
Parameters:
Name Type Description
type String

Type of hook - "onEnter" or "onExit"

name String

Name of Route

Returns:

Array of hooks

Type
Array

(static) onEnter(routeName, callback) → {undefined}

Register a hook on a specific route Can be called as many times as needed to add more than one callback

Source:
Example
// create a function to do something on the product detail page
function logSomeStuff() {
  console.log("We're arriving at the product page!");
}
// add that to the product detail page onEnter hook
Router.Hooks.onEnter("product", logSomeStuff);
Parameters:
Name Type Description
routeName String

Name of route

callback function

Callback method

Returns:
Type
undefined

(static) onExit(routeName, callback) → {undefined}

Register a hook on a specific route Can be called as many times as needed to add more than one callback

Source:
Parameters:
Name Type Description
routeName String

Name of route

callback function

Callback method

Returns:
Type
undefined

(static) run(type, name, contextopt) → {Array}

Run all registered hooks

Source:
Parameters:
Name Type Attributes Description
type String

Type of hook - "onEnter" or "onExit"

name String

"GLOBAL" for all registered global hooks

context Object <optional>

Context object, optional, or routeName

Returns:

Array of hooks

Type
Array