Commit 87109a12 by jutawuth nantawan

update route

1 parent 4fc3c2c4
Showing with 116 additions and 4 deletions
...@@ -416,12 +416,125 @@ import '../../resources/style/css/style.css'; ...@@ -416,12 +416,125 @@ import '../../resources/style/css/style.css';
## 4. Routing ## 4. Routing
route ### Switch
Switch เป็นการทำ Route แบบเปลี่ยนทั้งหน้า เมื่อ url เปลี่ยนหน้าจอจะแสดงผลที่ตรงกับ path ที่ระบุไว้เพียงหน้าจอเดียว โดยเรียงลำดับการแสดงผลจากบนลงล่าง
```javascript
// app.js
import React, { Component } from 'react';
import Routing from './routes/mainRoutes';
import './resources/style/css/App.css';
class App extends Component {
render() {
return <Routing eventEmitter={this.props.eventEmitter} />;
}
}
export default App;
```
import ไฟล์ mainRoutes.js เพื่อใช้ในการกำหนดเส้นทาง App.js
```javascript
// mainRoutes.js
import React from 'react';
import { Switch, Route } from 'react-router-dom';
import LoginPage from '../pages/login/LoginPage';
import MainPage from '../pages/main/MainPage';
export default ({ eventEmitter }) => (
<Switch>
<Route exact path="/" component={LoginPage} />
<Route path="/login" component={LoginPage} />
<Route
path="/process"
render={props => <MainPage eventEmitter={eventEmitter} {...props} />}
/>
</Switch>
);
```
### match
match เป็นการแสดงผล component เฉพาะส่วน ซึ่งสามารถทำงานภายใต้หน้าจอหลักได้
```javascript
// mainPage.jsx
import React from 'react';
import { Layout } from 'antd';
import ContentRoutes from '../../routes/contentRoutes';
export default class MainPage extends React.Component {
render() {
return (
<Layout style={{ minHeight: '100vh' }}>
<Header/>
<Sider/>
<Layout>
<Breadcrumb />
<div className="content" style={{ margin: 10 }}>
<ContentRoutes
match={this.props.match}
/>
</div>
<Footer />
</Layout>
</Layout>
);
}
}
```
import ไฟล์ contentRoutes.js เพื่อใช้ในการกำหนดเส้นทาง App.js
```javascript
//contentRoutes.js
import React from 'react';
import { Switch, Route } from 'react-router-dom';
import Content1 from '../pages/content/Content1';
import Content2 from '../pages/content/Content2';
import Content3 from '../pages/content/Content3';
import Home from '../pages/content/Home';
export default ({ match }) => {
return (
<Switch>
<Route path={`${match.url}/home`} component={Home} />
<Route path={`${match.url}/content1`} component={Content1} />
<Route path={`${match.url}/content2`} component={Content2} />
<Route path={`${match.url}/content3`} component={Content3} />
</Switch>
);
};
```
## 5. Calling API ## 5. Calling API
call call
## 6. Default Component Property & Behavior
default
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!