File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " use-react-router-breadcrumbs" ,
3
- "version" : " 1.0.2 " ,
3
+ "version" : " 1.0.3 " ,
4
4
"description" : " A hook for displaying and setting breadcrumbs for react router" ,
5
5
"main" : " dist/cjs/index.js" ,
6
6
"module" : " dist/es/index.js" ,
Original file line number Diff line number Diff line change @@ -396,4 +396,11 @@ describe('use-react-router-breadcrumbs', () => {
396
396
expect ( forwardedProps ) . toEqual ( 'prop forwarding works' ) ;
397
397
} ) ;
398
398
} ) ;
399
+
400
+ describe ( 'Edge cases' , ( ) => {
401
+ it ( 'Should handle 2 slashes in a URL (site.com/sandwiches//tuna)' , ( ) => {
402
+ const { breadcrumbs } = render ( { pathname : '/sandwiches//tuna' } ) ;
403
+ expect ( breadcrumbs ) . toBe ( 'Home / Sandwiches / Tuna' ) ;
404
+ } ) ;
405
+ } ) ;
399
406
} ) ;
Original file line number Diff line number Diff line change @@ -199,17 +199,20 @@ export const getBreadcrumbs = (
199
199
200
200
pathname
201
201
. split ( '?' ) [ 0 ]
202
- // Remove trailing slash "/" from pathname.
203
- . replace ( / \/ $ / , '' )
204
202
// Split pathname into sections.
205
203
. split ( '/' )
206
204
// Reduce over the sections and call `getBreadcrumbMatch()` for each section.
207
- . reduce ( ( previousSection : string , currentSection : string ) => {
205
+ . reduce ( ( previousSection : string , currentSection : string , index : number ) => {
208
206
// Combine the last route section with the currentSection.
209
207
// For example, `pathname = /1/2/3` results in match checks for
210
208
// `/1`, `/1/2`, `/1/2/3`.
211
209
const pathSection = ! currentSection ? '/' : `${ previousSection } /${ currentSection } ` ;
212
210
211
+ // Ignore trailing slash or double slashes in the URL
212
+ if ( pathSection === '/' && index !== 0 ) {
213
+ return '' ;
214
+ }
215
+
213
216
const breadcrumb = getBreadcrumbMatch ( {
214
217
currentSection,
215
218
location,
You can’t perform that action at this time.
0 commit comments