Skip to content

Commit

Permalink
fix: CBreadcrumbRouter: add route parameters support #118
Browse files Browse the repository at this point in the history
  • Loading branch information
woothu committed Jun 17, 2020
1 parent 4d68dc8 commit 6d8b59b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/breadcrumb/CBreadcrumbRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import React from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import { CBreadcrumb, CBreadcrumbItem } from '../index'
import { Link, useLocation } from 'react-router-dom';
import { Link, useLocation, matchPath } from 'react-router-dom';

//component - CoreUI / CBreadcrumbRouter

const getPaths = pathname => {
const paths = ['/']
if (pathname === '/') return paths;
Expand Down Expand Up @@ -33,25 +32,28 @@ const CBreadcrumbRouter = props => {

const {
className,
//
innerRef,
routes,
...attributes
} = props;
} = props

let items = null
if (routes) {
const currPath = useLocation().pathname
const paths = getPaths(currPath)
const currRoutes = routes.filter(route => paths.includes(route.path))
const currRoutes = paths.map(path => {
return routes.find(route => matchPath(path, {
path: route.path,
exact: route.exact
}))
}).filter(route => route)
items = currRoutes.map(route => {
return CBreadcrumbRouteItem(route, currPath)
})
}


//render

const classes = classNames(className)

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

CBreadcrumbRouter.propTypes = {
className: PropTypes.string,
//
innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
routes: PropTypes.array
}
Expand Down

0 comments on commit 6d8b59b

Please sign in to comment.