How to do it...

Let's say that your app has three URLs and you want tabs as the navigation mechanism to navigate between the routes. The first step is turning the Tab buttons into links. The second step is having Route components render the appropriate tab content, based on which one was clicked on. Here's the code:

import React, { useState } from 'react';
import { Route, Link } from 'react-router-dom';

import { withStyles } from '@material-ui/core/styles';
import AppBar from '@material-ui/core/AppBar';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
import Typography from '@material-ui/core/Typography';

const styles = theme => ({
root: {
flexGrow: 1,
backgroundColor: theme.palette.background.paper
},
tabContent: {
padding: theme.spacing(2)
}
});

function TabNavigationWithRoutes({ classes }) {
const [value, setValue] = useState(0);

const onChange = (e, value) => {
setValue(value);
};

return (
<div className={classes.root}>
<AppBar position="static">
<Tabs value={value} onChange={onChange}>
<Tab label="Item One" component={Link} to="/" />
<Tab label="Item Two" component={Link} to="/page2" />
<Tab label="Item Three" component={Link} to="/page3" />
</Tabs>
</AppBar>
<Route
exact
path="/"
render={() => (
<Typography component="div" className={classes.tabContent}>
Item One
</Typography>
)}
/>
<Route
exact
path="/page2"
render={() => (
<Typography component="div" className={classes.tabContent}>
Item Two
</Typography>
)}
/>
<Route
exact
path="/page3"
render={() => (
<Typography component="div" className={classes.tabContent}>
Item Three
</Typography>
)}
/>
</div>
);
}

export default withStyles(styles)(TabNavigationWithRoutes);

When you load the screen, the first tab should be selected and the first tab content should be rendered:

If you click on the ITEM TWO tab, you'll be taken to the /page2 URL. This results in the active Route component changing the tab content, and the changed tab state changes the selected tab: