From 6d8b59b9cfa145a30f4e54832941ce28ef514e29 Mon Sep 17 00:00:00 2001 From: woothu <32914662+woothu@users.noreply.github.com> Date: Wed, 17 Jun 2020 11:22:49 +0200 Subject: [PATCH] fix: CBreadcrumbRouter: add route parameters support #118 --- src/breadcrumb/CBreadcrumbRouter.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/breadcrumb/CBreadcrumbRouter.js b/src/breadcrumb/CBreadcrumbRouter.js index 7b5b36d5..500f1c06 100644 --- a/src/breadcrumb/CBreadcrumbRouter.js +++ b/src/breadcrumb/CBreadcrumbRouter.js @@ -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; @@ -33,17 +32,21 @@ 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) }) @@ -51,7 +54,6 @@ const CBreadcrumbRouter = props => { //render - const classes = classNames(className) return ( @@ -67,7 +69,6 @@ const CBreadcrumbRouter = props => { CBreadcrumbRouter.propTypes = { className: PropTypes.string, - // innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]), routes: PropTypes.array }