balderdashy/mast — pull request #96 by sgress454 (2013-05-17 18:50:12+00:00)
Title: Added ability to redirect mid-route from within a beforeRoute handler

Mast components currently trigger "beforeRoute" and "afterRoute" events when handling a route subscription. But there's currently no way to affect the routing from within one of these handlers--the classic case being a handler wanting to check the user's login status and redirect to login screen if necessary. This update adds on object argument to the "trigger" call that the event handler can modify to alert the component that some action should occur. Currently only redirection is supported; if the object is modified to have a "redirect" property, then after all of the handlers are run, the component will Mast.navigate() to that property's value instead of continuing on the route (the afterRoute event will *not* be triggered).

Note that changes to the object in one beforeRoute event handler will be visible to subsequent handlers. This method could be further fleshed out to provide a full middleware layer to the routing process.