@@ -46,6 +46,7 @@ const components = {
4646 ) ;
4747 } ,
4848 BreadcrumbMatchTest : ( { match } ) => < span > { match . params . number } </ span > ,
49+ BreadcrumbRouteTest : ( { match } ) => < span > { match . route ?. arbitraryProp } </ span > ,
4950 BreadcrumbNavLinkTest : ( { match } ) => < a to = { match . pathname } > Link</ a > ,
5051 BreadcrumbLocationTest : ( {
5152 location : {
@@ -166,6 +167,10 @@ components.BreadcrumbMatchTest.propTypes = {
166167 match : PropTypes . shape ( matchShape ) . isRequired ,
167168} ;
168169
170+ components . BreadcrumbRouteTest . propTypes = {
171+ match : PropTypes . shape ( matchShape ) . isRequired ,
172+ } ;
173+
169174components . BreadcrumbNavLinkTest . propTypes = {
170175 match : PropTypes . shape ( matchShape ) . isRequired ,
171176} ;
@@ -211,7 +216,10 @@ describe('use-react-router-breadcrumbs', () => {
211216 // test a `*` route
212217 { path : '*' , breadcrumb : 'Any' } ,
213218 ] ;
214- const { breadcrumbs, wrapper } = render ( { pathname : '/1/2/3/4/5' , routes } ) ;
219+ const { breadcrumbs, wrapper } = render ( {
220+ pathname : '/1/2/3/4/5' ,
221+ routes,
222+ } ) ;
215223 expect ( breadcrumbs ) . toBe ( 'Home / One / TWO / 3 / Link / Any' ) ;
216224 expect ( wrapper . find ( 'a' ) . props ( ) . to ) . toBe ( '/1/2/3/4' ) ;
217225 } ) ;
@@ -455,6 +463,21 @@ describe('use-react-router-breadcrumbs', () => {
455463 } ) ;
456464 } ) ;
457465
466+ describe ( 'When using the route object' , ( ) => {
467+ it ( 'should inject the matched route in the `match` property' , ( ) => {
468+ const routes = [
469+ {
470+ path : '/one' ,
471+ breadcrumb : components . BreadcrumbRouteTest ,
472+ arbitraryProp : 'foobar' ,
473+ } ,
474+ ] ;
475+
476+ const { breadcrumbs } = render ( { pathname : '/one' , routes } ) ;
477+ expect ( breadcrumbs ) . toBe ( 'Home / foobar' ) ;
478+ } ) ;
479+ } ) ;
480+
458481 describe ( 'Options' , ( ) => {
459482 describe ( 'excludePaths' , ( ) => {
460483 it ( 'Should not return breadcrumbs for specified paths' , ( ) => {
@@ -529,7 +552,9 @@ describe('use-react-router-breadcrumbs', () => {
529552
530553 it ( 'Should not support nested absolute paths' , ( ) => {
531554 expect ( ( ) => getMethod ( ) ( {
532- routes : [ { path : '/a' , breadcrumb : 'Yo' , children : [ { path : '/b' } ] } ] ,
555+ routes : [
556+ { path : '/a' , breadcrumb : 'Yo' , children : [ { path : '/b' } ] } ,
557+ ] ,
533558 location : { pathname : '/1' } ,
534559 } ) ) . toThrow (
535560 'useBreadcrumbs: The absolute path of the child route must start with the parent path' ,
@@ -538,11 +563,11 @@ describe('use-react-router-breadcrumbs', () => {
538563
539564 it ( 'Should error If the index route provides children' , ( ) => {
540565 expect ( ( ) => getMethod ( ) ( {
541- routes : [ { index : true , breadcrumb : 'Yo' , children : [ { path : '/b' } ] } ] ,
566+ routes : [
567+ { index : true , breadcrumb : 'Yo' , children : [ { path : '/b' } ] } ,
568+ ] ,
542569 location : { pathname : '/1' } ,
543- } ) ) . toThrow (
544- 'useBreadcrumbs: Index route cannot have child routes' ,
545- ) ;
570+ } ) ) . toThrow ( 'useBreadcrumbs: Index route cannot have child routes' ) ;
546571 } ) ;
547572 } ) ;
548573
0 commit comments