I'm using semantic-ui's Tab component and I have different components in each tab's pane. When I click on a tab, I would like the URL to change to "/tabname" so that a specific tab can be bookmarked by users who only need the functionality in that tab.
All the examples on the semantic-ui site define tabs like the code below.
const panes = [
{ menuItem: 'Component 1', render: () => <Tab.Pane><Component1 /></Tab.Pane> },
{ menuItem: 'Component 2', render: () => <Tab.Pane><Component2 /></Tab.Pane> }
]
render() {
return (
<Tab panes={panes} />
)
}
I tried changing the menuItem to:
{ menuItem: () => <NavLink to="/component2">Component 2</NavLink>, render: () => <Tab.Pane><Component2 /></Tab.Pane> }
Or this:
{ menuItem: () => <Menu.Item as={Link} to="/component2">Component 2</Menu.Item>, render: () => <Tab.Pane><Component2 /></Tab.Pane> }
and while it does make the link change, it also disables the tab switching (so clicking the 'Component 2' tab adds '/component2' to the URL, but <Component1 />
is still displayed in the pane). The issue is that the Tab's onClick event is overridden by Link's onClick event, so it breaks the tab switching.
There has to be a way to make a tab change the link AND change the pane content. The component augmentation feature of semantic-ui-react is supposed to solve these kinds of issues but it seems to fail with the Tab component. If only their documentation would not be paper thin.