Created
May 7, 2021 21:23
-
-
Save TunvirRahman/7aa1da31cf1f7fb8149d368c9cbbc8a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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