Skip to content

Instantly share code, notes, and snippets.

@loaiabdalslam
Created May 19, 2019 11:22
Show Gist options
  • Save loaiabdalslam/dacdada5e1982e4f625e7a6defe39896 to your computer and use it in GitHub Desktop.
Save loaiabdalslam/dacdada5e1982e4f625e7a6defe39896 to your computer and use it in GitHub Desktop.
This Gist will helping you to set routes name easly in your next express project | it's just abstract if you want to create your own package .
var env="http://localhost:3000/"
var route='users/:id/profile/'
var routes=[
{
'name':'profile',
'path':'users/:id/:profile/'
}
]
function RouteName(route,arg){
let targetRoute = routes.find(e=>e.name==route).path
for(var key in arg){
targetRoute=targetRoute.replace(`:${key}`,arg[key])
//console.log(targetRoute)
}
return targetRoute
}
console.log(env+RouteName('profile',{'id':3,'profile':'loaiabdalslam'}))
// output : 'http://localhost:3000/users/3/loaiabdalslam/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment