Skip to content

Commit 282cd1c

Browse files
React Router usage
1 parent 266aec5 commit 282cd1c

File tree

6 files changed

+77
-32
lines changed

6 files changed

+77
-32
lines changed

delivery/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"react": "^16.3.0",
77
"react-dom": "^16.3.0",
88
"react-flexbox-grid": "^2.0.0",
9+
"react-router": "^4.2.0",
10+
"react-router-dom": "^4.2.2",
911
"react-scripts": "1.1.2",
1012
"styled-components": "^3.2.5"
1113
},

delivery/public/index.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
<meta http-equiv="X-UA-Compatible" content="ie=edge">
77
<title>Delivery Club</title>
88
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Pacifico&amp;subset=cyrillic" rel="stylesheet">
9-
<!-- <link rel="stylesheet" href="https://unpkg.com/flexboxgrid2@7.2.1/flexboxgrid2.css">
10-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> -->
119
</head>
1210
<body>
13-
<main id="main"></main>
11+
<main id="root"></main>
1412
</body>
1513
</html>
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@ import { Grid, Row, Col } from 'react-flexbox-grid';
33
import styled from 'styled-components';
44

55
import Button from './Button';
6+
import Header from './Header';
67
import Header1 from './Header1';
78
import LeadText from './LeadText';
89
import StoreCard from './StoreCard';
10+
import Footer from './Footer';
11+
12+
const Homepage = () => (
13+
<div>
14+
<Header />
15+
<Description />
16+
<Footer />
17+
</div>
18+
);
919

1020
const DescriptionCover = styled.img.attrs({
1121
src: "img/picpizzaaa.jpg"
@@ -69,4 +79,4 @@ const Description = () => {
6979
)
7080
};
7181

72-
export default Description;
82+
export default Homepage;

delivery/src/components/Main.js

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
3+
import LeadText from './LeadText';
4+
5+
class Timepage extends React.Component {
6+
constructor(props) {
7+
super(props);
8+
this.state = {
9+
date: new Date()
10+
};
11+
}
12+
13+
tick() {
14+
this.setState({
15+
date: new Date()
16+
});
17+
}
18+
19+
componentDidMount() {
20+
this.timerID = setInterval(
21+
() => this.tick(),
22+
1000
23+
);
24+
}
25+
26+
componentWillUnmount() {
27+
clearInterval(this.timerID);
28+
}
29+
30+
render() {
31+
return (
32+
<div>
33+
<LeadText>{ this.state.date.toLocaleTimeString() }</LeadText>
34+
</div>
35+
);
36+
}
37+
}
38+
39+
export default Timepage;

delivery/src/index.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
import React from 'react';
2-
import {render} from 'react-dom';
2+
import { render } from 'react-dom';
33
import { injectGlobal } from 'styled-components';
44

5-
import Main from './components/Main';
5+
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
6+
7+
import Homepage from './components/Homepage';
8+
import Timepage from './components/Timepage';
69

710
injectGlobal`
8-
body {
9-
margin: 0;
10-
font-family: "Open Sans", sans-serif;
11-
}
11+
body {
12+
margin: 0;
13+
font-family: "Open Sans", sans-serif;
14+
}
1215
13-
header {
14-
background-image: url(img/bg.jpg);
15-
background-repeat: no-repeat;
16-
background-size: cover;
17-
padding-bottom: 75px;
18-
}
16+
header {
17+
background-image: url(img/bg.jpg);
18+
background-repeat: no-repeat;
19+
background-size: cover;
20+
padding-bottom: 75px;
21+
}
1922
`
2023

21-
render(<Main/>, document.getElementById('main'))
24+
render(
25+
<Router>
26+
<Switch>
27+
<Route exact path='/' component={Homepage} />
28+
<Route exact path='/time' component={Timepage} />
29+
</Switch>
30+
</Router>,
31+
document.getElementById('root')
32+
);

0 commit comments

Comments
 (0)