You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
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 (
|
|
|
|
<RouterSwitch>
|
|
|
|
{
|
|
|
|
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 });
|
|
|
|
})
|
|
|
|
}
|
|
|
|
</RouterSwitch>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Switch.propTypes = {
|
|
|
|
children: PropTypes.node.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Switch;
|