interface Events { routeChangeStart : [ url : string ] ; routeChangeComplete : [ url : string ] ; routeChangeError : [ err : Error , url : string ] ; } export type RouterEventsInternal = ReturnType < typeof routerEvents > ; export type RouterEvents = Omit < ReturnType < typeof routerEvents > , "dispose" > ; export const routerEvents = ( ) => { const listeners = Object . create ( null ) ; return { on < K extends keyof Events > ( event , callback ) { ( listeners [ event ] = listeners [ event ] ?? [ ] ) . push ( callback ) ; } , off < K extends keyof Events > ( event , callback ) { listeners [ event ] = ( listeners [ event ] ?? [ ] ) . filter ( ( listener ) => listener !== callback ) ; } , emit < K extends keyof Events > ( event , args ) { ( listeners [ event ] ?? [ ] ) . forEach ( ( listener ) => listener ( ... args ) ) ; } , } ; } ;