Skip to content

Instantly share code, notes, and snippets.

@TunvirRahman
Created May 7, 2021 21:23
Show Gist options
  • Select an option

  • Save TunvirRahman/7aa1da31cf1f7fb8149d368c9cbbc8a7 to your computer and use it in GitHub Desktop.

Select an option

Save TunvirRahman/7aa1da31cf1f7fb8149d368c9cbbc8a7 to your computer and use it in GitHub Desktop.
const UserRole = {
ADMIN: "Admin",
GENERAL_USER: "GeneralUser",
SUPER_ADMIN: "SuperAdmin",
};
function getRoute(userRole = "default role"){
switch(userRole){
case UserRole.ADMIN:
return "/admin"
case UserRole.GENERAL_USER:
return "/GENERAL_USER"
case UserRole.SUPER_ADMIN:
return "/superadmin"
default:
return "/"
}
}
console.log(getRoute(UserRole.ADMIN)) // return "/admin"
console.log(getRoute("Anything")) // return Default path
console.log(getRoute()) // return Default path
console.log(getRoute(null)) // return Default path
// More cases if new arrive
// You can think if else instead of switch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment