Repository URL to install this package:
|
Version:
7.0.3 ▾
|
import { isObj } from 'exotic'
import matchPath from 'react-router-dom/matchPath'
import { routePathsList, routePathCurrent } from './routes'
// @TODO @FIXME some issue with import order
// import routes from 'bootstrapper/routes'
/**
* @description what this does is match our params in bootstrapper/routes
* @param {*} pathname
*/
function matchRouteParams(pathname) {
let matched = {}
// go through our routes
// use the sealed object for perf
// match params (which has a cache)
// merge with matched object
// return matched
for (let index = 0; index < routePathsList.length; index++) {
const matchablePath = routePathsList[index]
routePathCurrent.path = matchablePath
const matchedFromPath = matchPath(pathname, routePathCurrent)
if (isObj(matchedFromPath)) {
// this.log(pathname, { routePathCurrent, matchedFromPath, pathname })
Object.assign(matched, matchedFromPath.params)
// access to which route had the data
// Object.defineProperty(matched, '@@matches', {
// writable: false,
// configurable: false,
// enumerable: false,
// value: matchedFromPath,
// })
}
}
// if (this.props && isObj(this.props.match)) {
// matched = {
// ...matched,
// ...this.props.match,
// ...this.props.match.params,
// }
// } else {
// matched.match = matched
// }
}
export {
matchRouteParams,
// routePathsList,
}