Skip to content

Instantly share code, notes, and snippets.

@argodeep
Created September 26, 2020 15:47
Show Gist options
  • Save argodeep/c2367111b48234ec3307dfc325c77b0d to your computer and use it in GitHub Desktop.
Save argodeep/c2367111b48234ec3307dfc325c77b0d to your computer and use it in GitHub Desktop.
Breadcrumb using recursive function
const routes = ['home', 'grids', 'grid1'];
const breadcrumbs = [];
let level = 0;
while(level < routes.length) {
breadcrumbs.push(routeTitleLink(routes.slice(0, level+1))); // calling recursive function for each route.
level++
}
console.log(breadcrumbs)
function routeTitleLink(route) {
return {
title: route.slice(-1).toString().substr(0,1).toUpperCase() + route.slice(-1).toString().substr(1),
link: route.join('/')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment