import React from 'react'; import { shape, string, number, element, arrayOf } from 'prop-types'; import { Tab, Tabs, TabTitleText } from '@patternfly/react-core'; import { Switch, Route, Redirect, useLocation, withRouter, HashRouter } from 'react-router-dom'; import { head, last } from 'lodash'; const RoutedTabs = ({ tabs, defaultTabIndex, }) => { const { hash, key: locationKey, } = useLocation(); // The below transforms #/history/6 to history const currentTabFromUrl = head(last(hash.split('#/')).split('/')); return ( <> {tabs.map(({ key, title }) => ( {title}} /> ))}
{tabs.map(({ key, content }) => ( {content} ))}
); }; RoutedTabs.propTypes = { tabs: arrayOf(shape({ key: string.isRequired, title: string.isRequired, content: element.isRequired, })).isRequired, defaultTabIndex: number, }; RoutedTabs.defaultProps = { defaultTabIndex: 0, }; export default withRouter(RoutedTabs);