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.
Thanks! This is awesome. I need to do something similar in beforeClose as well, to give access to a callback as an argument that you can trigger when you're done and "finish off" the component.
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.