Skip to content

Commit 4c9ced0

Browse files
committed
hide navbar on mobile when page changes
1 parent 3d0d5b9 commit 4c9ced0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Component/Navbar.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
AppBar, Drawer, Hidden, IconButton, List, ListItem,
44
ListItemIcon, ListItemText, makeStyles, Toolbar, Typography
55
} from "@material-ui/core";
6-
import {Link} from "react-router-dom";
6+
import {Link, useHistory} from "react-router-dom";
77
import * as PropTypes from "prop-types";
88
import MenuIcon from '@material-ui/icons/Menu';
99

@@ -52,6 +52,7 @@ const useStyles = makeStyles((theme) => {
5252
export default function Navbar({routes}) {
5353
const classes = useStyles();
5454
const [open, setOpen] = React.useState(false);
55+
const history = useHistory();
5556

5657
const handleDrawerOpen = () => {
5758
setOpen(true);
@@ -104,7 +105,7 @@ export default function Navbar({routes}) {
104105
<List>
105106
{routes.map((route, index) => {
106107
return (
107-
<ListItem button key={"nav_" + index} component={Link} to={Array.isArray(route.path)? route.path[0]: route.path}>
108+
<ListItem button key={"nav_" + index} component={Link} onClick={()=>{setOpen(false);history.push(Array.isArray(route.path)? route.path[0]: route.path);}}>
108109
<ListItemIcon>{route.icon}</ListItemIcon>
109110
<ListItemText primary={route.name} />
110111
</ListItem>

0 commit comments

Comments
 (0)