Skip to content

Instantly share code, notes, and snippets.

@syed-ahmad
Created October 25, 2023 16:07
Show Gist options
  • Save syed-ahmad/55db6dcec45190f7a11b49750e433291 to your computer and use it in GitHub Desktop.
Save syed-ahmad/55db6dcec45190f7a11b49750e433291 to your computer and use it in GitHub Desktop.
Generate breadcrumb href
function generateBreadcrumbs(paths) {
var breadcrumbs = [];
breadcrumbs.push({
name: 'Home',
href: '/',
});
paths.forEach((path, index) => {
let segments = [];
for(i = 0; i <= index; i++) {
segments.push(paths[i]);
}
breadcrumbs.push({
name: path,
...(index < paths.length - 1 ? { href: '/' + segments.join('/') } : null),
});
});
return breadcrumbs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment