@@ -2,10 +2,9 @@ import React from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import classNames from 'classnames'
4
4
import { CBreadcrumb , CBreadcrumbItem } from '../index'
5
- import { Link , useLocation } from 'react-router-dom' ;
5
+ import { Link , useLocation , matchPath } from 'react-router-dom' ;
6
6
7
7
//component - CoreUI / CBreadcrumbRouter
8
-
9
8
const getPaths = pathname => {
10
9
const paths = [ '/' ]
11
10
if ( pathname === '/' ) return paths ;
@@ -33,25 +32,28 @@ const CBreadcrumbRouter = props => {
33
32
34
33
const {
35
34
className,
36
- //
37
35
innerRef,
38
36
routes,
39
37
...attributes
40
- } = props ;
38
+ } = props
41
39
42
40
let items = null
43
41
if ( routes ) {
44
42
const currPath = useLocation ( ) . pathname
45
43
const paths = getPaths ( currPath )
46
- const currRoutes = routes . filter ( route => paths . includes ( route . path ) )
44
+ const currRoutes = paths . map ( path => {
45
+ return routes . find ( route => matchPath ( path , {
46
+ path : route . path ,
47
+ exact : route . exact
48
+ } ) )
49
+ } ) . filter ( route => route )
47
50
items = currRoutes . map ( route => {
48
51
return CBreadcrumbRouteItem ( route , currPath )
49
52
} )
50
53
}
51
54
52
55
53
56
//render
54
-
55
57
const classes = classNames ( className )
56
58
57
59
return (
@@ -67,7 +69,6 @@ const CBreadcrumbRouter = props => {
67
69
68
70
CBreadcrumbRouter . propTypes = {
69
71
className : PropTypes . string ,
70
- //
71
72
innerRef : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . func , PropTypes . string ] ) ,
72
73
routes : PropTypes . array
73
74
}
0 commit comments