import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { Switch as RouterSwitch } from 'react-router-dom'; import { map } from 'Helpers/elementChildren'; import getPathWithUrlBase from 'Utilities/getPathWithUrlBase'; class Switch extends Component { // // Render render() { const { children } = this.props; return ( { map(children, (child) => { const { path: childPath, addUrlBase = true } = child.props; if (!childPath) { return child; } const path = addUrlBase ? getPathWithUrlBase(childPath) : childPath; return React.cloneElement(child, { path }); }) } ); } } Switch.propTypes = { children: PropTypes.node.isRequired }; export default Switch;