From 62a21ed9ead249a628a208e6be4cf021595a324d Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Mon, 29 Jun 2020 12:42:09 -0700 Subject: [PATCH] fix: Ensure urls with trailing slashes are matched properly when creating breadcrumbs --- src/utils/create-breadcrumbs.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/create-breadcrumbs.js b/src/utils/create-breadcrumbs.js index 8127b9b3e..9b9e9d235 100644 --- a/src/utils/create-breadcrumbs.js +++ b/src/utils/create-breadcrumbs.js @@ -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: @@ -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) {