I have a react component, that uses material-ui tabs
and react-swipeable-views
. The problem I am experiencing is that, when switching tabs, the url displayed does not change, I noticed that is the react-swipeable-views logic. I would like to apply react-router
as well in order to change the urls on tab change while preserving the react-swipeable-view logic.
Here is a part of my code below with some additional details:
import SwipeableViews from 'react-swipeable-views';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
export default function TasksViewTabs(props) {
const task = props.match.params.taskid
const classes = useStyles();
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
console.log('new value', newValue)
setValue(newValue);
};
const handleChangeIndex = (index) => {
setValue(index);
};
console.log('value', value)
return (
<>
<Tabs value={value} onChange={handleChange} classes={{indicator: classes.indicator}}>
<Tab className={value === 0? classes.active_tabStyle : null} label="Runs" {...a11yProps(0)} />
<Tab className={value === 1? classes.active_tabStyle : null} label="Tasks" {...a11yProps(1)} />
<Tab className={value === 2? classes.active_tabStyle : null} label="Settings" {...a11yProps(2)} />
</Tabs>
<SwipeableViews index={value} onChangeIndex={handleChangeIndex}>
<RunApp value={value} index={0} taskid={task} />
<TaskApp value={value} index={1} taskid={task} />
<SettingsApp value={value} index={2} taskid={task} />
</SwipeableViews>
</>
);
}
The default url displaying looks like this, it doesn't change when view is changed : localhost:3000/clusters/<task:id>
But I have three tabs (runs
, tasks
, settings
), which control the react-swipeable-views.
I want the url to display like (localhost:3000/clusters/<task:id>/runs
, localhost:3000/clusters/<task:id>/tasks
, localhost:3000/clusters/<task:id>/settings
) respectively on tab change.
How can I achieve that and preserve the react-swipeable logic?
Thanks
Just incase, the url is loaded from a history.push from a component that contains a table. only on clicking a table row.
rowClicked = (params) => {
return (
history.push({
pathname: `/clusters/${params.data.md5_hash}`
})
)
}
Thanks, I hope that this helps :)