From a1abf2528827d45044621c46c6b06c750c2cd78b Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Thu, 11 Jun 2020 14:17:19 +0300 Subject: [PATCH] added routing --- client/package.json | 1 + client/src/App.js | 20 +++++-- client/src/components/Header/Header.js | 36 +++++++++-- client/src/components/Layout/Layout.js | 4 +- client/src/components/Nav/Nav.js | 6 +- .../components/Nav/NavContent/NavContent.js | 59 +++++++++++-------- client/src/containers/Category/Category.js | 33 +++++++++++ client/src/containers/NotFound/NotFound.js | 16 +++++ client/src/containers/Todos/Todos.js | 2 +- client/src/containers/Trash/Trash.js | 16 +++++ client/src/index.js | 12 ++-- 11 files changed, 162 insertions(+), 43 deletions(-) create mode 100644 client/src/containers/Category/Category.js create mode 100644 client/src/containers/NotFound/NotFound.js create mode 100644 client/src/containers/Trash/Trash.js diff --git a/client/package.json b/client/package.json index a29d9f4..af66074 100644 --- a/client/package.json +++ b/client/package.json @@ -7,6 +7,7 @@ "@material-ui/icons": "^4.9.1", "apollo-boost": "^0.4.9", "graphql": "^15.1.0", + "history": "^4.10.1", "react": "^16.13.1", "react-apollo": "^3.1.5", "react-dom": "^16.13.1", diff --git a/client/src/App.js b/client/src/App.js index 0c72592..ad30557 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,18 +1,30 @@ import React from 'react' -//import { BrowserRouter, Route, Switch } from 'react-router-dom' +import { Route, Switch, Redirect, withRouter } from "react-router-dom" import Layout from './components/Layout/Layout' import Todos from './containers/Todos/Todos' +import Category from './containers/Category/Category' +import Trash from './containers/Trash/Trash' +import NotFound from './containers/NotFound/NotFound' import CssBaseLine from '@material-ui/core/CssBaseline' -export default function App() { +const App = ({ history }) => { return ( <> - - + + + + + + {/* */} + + + ) } +export default withRouter(App) + diff --git a/client/src/components/Header/Header.js b/client/src/components/Header/Header.js index 9a54f53..8fb7f12 100644 --- a/client/src/components/Header/Header.js +++ b/client/src/components/Header/Header.js @@ -2,14 +2,25 @@ import React from 'react'; import AppBar from '@material-ui/core/AppBar'; import IconButton from '@material-ui/core/IconButton'; import MenuIcon from '@material-ui/icons/Menu'; +import CategoryIcon from '@material-ui/icons/Category'; +import DeleteIcon from '@material-ui/icons/Delete'; +import ErrorIcon from '@material-ui/icons/Error'; import Toolbar from '@material-ui/core/Toolbar'; import Typography from '@material-ui/core/Typography' +import FormatListBulletedIcon from '@material-ui/icons/FormatListBulleted'; import { makeStyles } from '@material-ui/core/styles' import Nav from '../Nav/Nav' const drawerWidth = 240; const useStyles = makeStyles((theme) => ({ + pageHeading: { + display: 'flex', + alignItems: 'center', + }, + pageHeadingImg: { + marginRight: 10 + }, appBar: { [theme.breakpoints.up('sm')]: { width: `calc(100% - ${drawerWidth}px)`, @@ -24,14 +35,31 @@ const useStyles = makeStyles((theme) => ({ }, })); -const Header = () => { +const renderHeading = (history, classes) => { + const { pathname } = history.location + + if (pathname.split('/')[1] === 'category') { + return Категория {pathname.split('/')[2]} + } + + switch(pathname) { + case '/': + return Список дел + case '/trash': + return Корзина + default: + return Ошибка + } +} + +const Header = ({ history }) => { const classes = useStyles(); const [mobileOpen, setMobileOpen] = React.useState(false); const handleDrawerToggle = () => { setMobileOpen(!mobileOpen); }; - + return ( <> @@ -46,11 +74,11 @@ const Header = () => { - Список дел + {renderHeading(history, classes)} -