class Router {
    constructor(rootPath="/", callback) {
        /**
         * @type {RegExp[]}
         */
        this.rootPath = rootPath
        this.routes = []
        this.current = undefined
        this.callback = callback
    }

    add(path, obj) {
        this.routes.push([path, obj])
    }

    route(path) {
        let to = this.routes.findIndex((r, i)=>r[0]instanceof RegExp?r[0].test(path):r[0]===path)
        this.current = this.routes[to]
        console.log('Routing to '+this.current[1])
        this.callback(this.current)
    }
}

export default Router