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
Parameters:
Name | Type | Description |
---|---|---|
type |
String | Type of hook - |
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
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
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
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
String | Type of hook - |
|
name |
String | "GLOBAL" for all registered global hooks |
|
context |
Object |
<optional> |
Context object, optional, or |
Returns:
Array of hooks
- Type
- Array