Skip to content

Instantly share code, notes, and snippets.

@alexalannunes
Last active October 19, 2021 17:30
Show Gist options
  • Save alexalannunes/677db9cf5fbe4fc75cb94d6a74a96c3f to your computer and use it in GitHub Desktop.
Save alexalannunes/677db9cf5fbe4fc75cb94d6a74a96c3f to your computer and use it in GitHub Desktop.
get route by children routes [test]
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