Last active
October 19, 2021 17:30
-
-
Save alexalannunes/677db9cf5fbe4fc75cb94d6a74a96c3f to your computer and use it in GitHub Desktop.
get route by children routes [test]
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 routes = [ | |
{ | |
route: '/registers/company', | |
childrens: [ | |
"/registers/company/:companyId/edit", | |
"/registers/company/new", | |
] | |
} | |
] | |
const currentRoute = '/registers/company/new'; | |
const currentRoute2 = '/registers/company/24/edit' | |
const transform = (route, paramName) => { | |
return route.replace(/\d{1,}/, paramName); | |
} | |
const currentUrl = transform(currentRoute2, ':companyId'); // or currentRoute | |
// const currentUrl = currentRoute; | |
const routeFind = routes.find(i => { | |
return i.childrens.includes(currentUrl); | |
}) | |
routeFind; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment