Skip to content

Commit 6d8b59b

Browse files
committed
fix: CBreadcrumbRouter: add route parameters support #118
1 parent 4d68dc8 commit 6d8b59b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/breadcrumb/CBreadcrumbRouter.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import React from 'react'
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44
import { CBreadcrumb, CBreadcrumbItem } from '../index'
5-
import { Link, useLocation } from 'react-router-dom';
5+
import { Link, useLocation, matchPath } from 'react-router-dom';
66

77
//component - CoreUI / CBreadcrumbRouter
8-
98
const getPaths = pathname => {
109
const paths = ['/']
1110
if (pathname === '/') return paths;
@@ -33,25 +32,28 @@ const CBreadcrumbRouter = props => {
3332

3433
const {
3534
className,
36-
//
3735
innerRef,
3836
routes,
3937
...attributes
40-
} = props;
38+
} = props
4139

4240
let items = null
4341
if (routes) {
4442
const currPath = useLocation().pathname
4543
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)
4750
items = currRoutes.map(route => {
4851
return CBreadcrumbRouteItem(route, currPath)
4952
})
5053
}
5154

5255

5356
//render
54-
5557
const classes = classNames(className)
5658

5759
return (
@@ -67,7 +69,6 @@ const CBreadcrumbRouter = props => {
6769

6870
CBreadcrumbRouter.propTypes = {
6971
className: PropTypes.string,
70-
//
7172
innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
7273
routes: PropTypes.array
7374
}

0 commit comments

Comments
 (0)