Skip to content

Commit

Permalink
fix: Ensure urls with trailing slashes are matched properly when crea…
Browse files Browse the repository at this point in the history
…ting breadcrumbs
  • Loading branch information
jerelmiller committed Jun 29, 2020
1 parent b09e543 commit 62a21ed
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils/create-breadcrumbs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const URL_WITH_TRAILING_SLASH = /(.+)\/$/;

/**
* Create a flat array of breadcrumbs for a given relative url given the
* site structure (sidenav). Returns an empty array if no match found. NOTE:
Expand All @@ -20,7 +22,11 @@ const createBreadcrumbs = (url, links, result = []) => {
}

// check to see if any of the links at this level match the path
const match = links.find((link) => link.url === url);
const match = links.find(
(link) =>
link.url === url ||
link.url === url.replace(URL_WITH_TRAILING_SLASH, '$1')
);

// if we have a link, return the displayName at the end of the result
if (match) {
Expand Down

0 comments on commit 62a21ed

Please sign in to comment.