Created
January 21, 2019 11:55
-
-
Save thecreazy/0c96fa0a7b04a684d6edf9bc45d2a4f3 to your computer and use it in GitHub Desktop.
Add and remove functions to the router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Router{ | |
routes: [] | |
mode: null | |
root: '/' | |
constructor(){ | |
this.mode = !!(history.pushState) ? 'history' : 'hash'; | |
} | |
add: (path, cb) => { | |
this.routes.push({path, cb}); | |
return this; | |
} | |
remove: path => { | |
for(var i in this.routes){ | |
if(routres[i].path === 'path'){ | |
this.routes.slice(i, 1); | |
return this;; | |
} | |
} | |
} | |
flush: ()=>{ | |
this.routes = []; | |
return this; | |
} | |
} | |
export default new Router() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment