Skip to content

Commit 8bbd77b

Browse files
add router; add a template;
1 parent a86325a commit 8bbd77b

File tree

17 files changed

+750
-35
lines changed

17 files changed

+750
-35
lines changed

config/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ module.exports = function (webpackEnv) {
328328
// Support React Native Web
329329
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
330330
'react-native': 'react-native-web',
331+
'@': path.resolve(__dirname, '../src'),
331332
// Allows for better profiling with ReactDevTools
332333
...(isEnvProductionProfile && {
333334
'react-dom$': 'react-dom/profiling',

package-lock.json

Lines changed: 32 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"eslint-webpack-plugin": "^2.5.2",
3636
"file-loader": "6.1.1",
3737
"fs-extra": "^9.0.1",
38+
"history": "^5.0.1",
3839
"html-webpack-plugin": "4.5.0",
3940
"identity-obj-proxy": "3.0.0",
4041
"jest": "26.6.0",

src/App.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
import styles from './App.module.less';
2-
import Sample from './components/sample/Sample';
2+
import HomePage from './pages/HomePage';
3+
import PageOne from './pages/PageOne';
4+
import PageTwo from './pages/PageTwo';
5+
import PageThree from './pages/PageThree';
6+
import PageFour from './pages/PageFour';
7+
import { withRouter, Route, Switch } from 'react-router-dom';
8+
39

410
function App() {
511
return (
612
<div className={styles.App}>
7-
<Sample/>
13+
<Switch>
14+
<Route path="/" component={HomePage} exact />
15+
<Route path="/page1" component={PageOne} />
16+
<Route path="/page2" component={PageTwo} />
17+
<Route path="/page3" component={PageThree} />
18+
<Route path="/page4" component={PageFour} />
19+
</Switch>
820
</div>
921
);
1022
}
1123

12-
export default App;
24+
export default withRouter(App);

src/App.module.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.App {
2+
padding: 16px;
23
text-align: center;
3-
margin-top: 100px;
44
display: flex;
55
flex-direction: column;
66
align-items: center;

src/components/Template/index.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import React from 'react';
2+
import styles from './index.module.less';
3+
4+
class Template extends React.Component {
5+
// init data
6+
constructor(props) {
7+
super(props);
8+
9+
this.state = {
10+
// data that will be used/changed in render function,
11+
// here to initiate them
12+
// you can see "state" as an Object.
13+
14+
isButtonClicked: false,
15+
count: 0,
16+
17+
}
18+
// Every function that interfaces with UI and data used
19+
// in this class needs to bind like this:
20+
this.someFunction1 = this.someFunction1.bind(this);
21+
this.someFunction2 = this.someFunction2.bind(this);
22+
this.handleOnClickBtn = this.handleOnClickBtn.bind(this);
23+
}
24+
25+
someFunction1() {
26+
return
27+
}
28+
29+
someFunction2() {
30+
return
31+
}
32+
33+
handleOnClickBtn() {
34+
console.log('count =',this.state.count);
35+
let currentCount = this.state.count;
36+
// Every time you wants to modify the variables you declared in this.state,
37+
// You need to use this function.
38+
this.setState({
39+
isButtonClicked: true,
40+
count: currentCount + 1,
41+
});
42+
}
43+
44+
componentDidMount() {
45+
// this is a function that will automatically be called the first time the component renders
46+
}
47+
48+
componentDidUpdate() {
49+
// this is a function that will automatically be called each time the component renders
50+
}
51+
52+
render() {
53+
return (
54+
<div className={styles.template}>
55+
<p>this is a template component!</p>
56+
<span>this is a link to <a href="/">homepage</a></span>
57+
<div>
58+
<div>Here is a count button</div>
59+
<div>
60+
<button onClick={this.handleOnClickBtn}>
61+
{
62+
this.state.isButtonClicked?
63+
"clicked!":"click me"
64+
}
65+
</button>
66+
</div>
67+
<div>You have clicked {this.state.count} time(s)!</div>
68+
</div>
69+
</div>
70+
);
71+
}
72+
73+
}
74+
75+
export default Template;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.template {
2+
background: skyblue;
3+
}

src/components/sample/Sample.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { Stage, Container, withPixiApp, Sprite, Graphics, useTick } from '@inlet/react-pixi';
33
import styles from './Sample.module.less';
44

5-
const Inner = () => {
5+
function Inner () {
66
const [x, setX] = React.useState(0);
77
const mask = React.useRef();
88
const i = React.useRef(0);
@@ -13,7 +13,7 @@ const Inner = () => {
1313
});
1414

1515
return (
16-
<Container position={[750, 250]}>
16+
<Container position={[250, 250]}>
1717
<Sprite
1818
image="https://s3-us-west-2.amazonaws.com/s.cdpn.io/693612/IaUrttj.png"
1919
scale={[4, 4]}
@@ -32,13 +32,13 @@ const Inner = () => {
3232
/>
3333
</Container>
3434
);
35-
};
35+
};
3636

3737
function Sample() {
3838
return (
3939
<div className={styles.sampleBox}>
4040
<a>learn react</a>
41-
<Stage width={1500} height={500} options={{ backgroundColor: 0xcccccc }}>
41+
<Stage width={500} height={500} options={{ backgroundColor: 0xcccccc }}>
4242
<Inner />
4343
</Stage>
4444
</div>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.sampleBox {
2-
background-color: red;
3-
width: 1800px;
2+
background-color: #123;
3+
width: 800px;
44
}

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import ReactDOM from 'react-dom';
33
import './index.css';
44
import App from './App';
55
import reportWebVitals from './reportWebVitals';
6+
import { BrowserRouter as Router } from 'react-router-dom';
67

78
ReactDOM.render(
89
<React.StrictMode>
9-
<App />
10+
<Router>
11+
<App />
12+
</Router>
1013
</React.StrictMode>,
1114
document.getElementById('root')
1215
);

0 commit comments

Comments
 (0)