Skip to content

Instantly share code, notes, and snippets.

@thecreazy
Created January 21, 2019 11:55
Show Gist options
  • Save thecreazy/0c96fa0a7b04a684d6edf9bc45d2a4f3 to your computer and use it in GitHub Desktop.
Save thecreazy/0c96fa0a7b04a684d6edf9bc45d2a4f3 to your computer and use it in GitHub Desktop.
Add and remove functions to the router
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