React/Material-UIでDrawer&Routingを実装
12539 ワード
./src/components/ui/Header.js
import React, { useState } from "react";
import {
AppBar,
Divider,
Drawer,
IconButton,
List,
ListItem,
ListItemText,
Toolbar,
Typography,
} from "@material-ui/core";
import MenuIcon from "@material-ui/icons/Menu";
import ChevronLeftIcon from "@material-ui/icons/ChevronLeft";
import MapIcon from "@material-ui/icons/Map";
import TimelineIcon from "@material-ui/icons/Timeline";
import ChatIcon from "@material-ui/icons/Chat";
const Header = () => {
const [open, setOpen] = useState(false);
const handleDrawerOpen = () => {
setOpen(true);
};
const handleDrawerClose = () => {
setOpen(false);
};
return (
<div>
<AppBar>
<Toolbar>
<IconButton onClick={handleDrawerOpen}>
<MenuIcon />
</IconButton>
<Typography>Header</Typography>
</Toolbar>
</AppBar>
<Drawer open={open}>
<IconButton onClick={handleDrawerClose}>
<ChevronLeftIcon />
</IconButton>
<Divider />
<List>
<ListItem button="AAAAA">
<MapIcon />
<ListItemText primary="AAAAA" />
</ListItem>
<ListItem button="BBBBB">
<TimelineIcon />
<ListItemText primary="BBBBB" />
</ListItem>
<ListItem button="CCCCC">
<ChatIcon />
<ListItemText primary="CCCCC" />
</ListItem>
</List>
</Drawer>
</div>
);
};
export default Header;
./src/App.js
import logo from "./logo.svg";
import "./App.css";
import Header from "./components/ui/Header";
import { BrowserRouter, Route, Switch } from "react-router-dom";
function App() {
return (
<div className="App">
<BrowserRouter>
<Header />
<Switch>
<Route exact path="/" component={() => <div>/</div>} />
<Route exact path="/AAAAA" component={() => <div>AAAAA</div>} />
<Route exact path="/BBBBB" component={() => <div>BBBBB</div>} />
<Route exact path="/CCCCC" component={() => <div>CCCCC</div>} />
</Switch>
</BrowserRouter>
</div>
);
}
export default App;
Author And Source
この問題について(React/Material-UIでDrawer&Routingを実装), 我々は、より多くの情報をここで見つけました https://qiita.com/yono2844/items/6d961e6b776f70431eed著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .