Merge pull request #2080 from tormjens/patch-1

Dispatch event when firing routes
This commit is contained in:
Ben Word
2018-11-16 12:13:34 -07:00
committed by GitHub

View File

@@ -25,6 +25,14 @@ class Router {
* @param {string} [arg] Any custom argument to be passed to the event.
*/
fire(route, event = 'init', arg) {
document.dispatchEvent(new CustomEvent('routed', {
bubbles: true,
detail: {
route,
fn: event,
},
}));
const fire = route !== '' && this.routes[route] && typeof this.routes[route][event] === 'function';
if (fire) {
this.routes[route][event](arg);