Merge pull request #2080 from tormjens/patch-1
Dispatch event when firing routes
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user