Skip to content

Commit

Permalink
Step 7. 添加layout
Browse files Browse the repository at this point in the history
  • Loading branch information
JobbyM committed Apr 26, 2017
1 parent 8bd76c7 commit 404d040
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 12 deletions.
28 changes: 28 additions & 0 deletions src/components/MainLayout/Header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { Menu, Icon } from 'antd';
import { Link } from 'dva/router';

function Header({ location }) {
return (
<Menu
selectedKeys={[location.pathname]}
mode="horizontal"
theme="dark"
>
<Menu.Item key="/users">
<Link to="/users"><Icon type="bars" />Users</Link>
</Menu.Item>
<Menu.Item key="/">
<Link to="/"><Icon type="home" />Home</Link>
</Menu.Item>
<Menu.Item key="/404">
<Link to="/page-you-dont-know"><Icon type="frown-circle" />404</Link>
</Menu.Item>
<Menu.Item key="/antd">
<a href="https://github.com/dvajs/dva" target="_blank">dva</a>
</Menu.Item>
</Menu>
);
}

export default Header;
16 changes: 16 additions & 0 deletions src/components/MainLayout/MainLayout.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

.normal {
display: flex;
flex-direction: column;
height: 100%;
}

.content {
flex: 1;
display: flex;
}

.main {
padding: 0 8px;
flex: 1 0 auto;
}
18 changes: 18 additions & 0 deletions src/components/MainLayout/MainLayout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import styles from './MainLayout.css';
import Header from './Header';

function MainLayout({ children, location }) {
return (
<div className={styles.normal}>
<Header location={location} />
<div className={styles.content}>
<div className={styles.main}>
{children}
</div>
</div>
</div>
);
}

export default MainLayout;
19 changes: 11 additions & 8 deletions src/routes/IndexPage.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import React from 'react';
import { connect } from 'dva';
import styles from './IndexPage.css';
import MainLayout from '../components/MainLayout/MainLayout';

function IndexPage() {
return (
<div className={styles.normal}>
<h1 className={styles.title}>Yay! Welcome to dva!</h1>
<div className={styles.welcome} />
<ul className={styles.list}>
<li>To get started, edit <code>src/index.js</code> and save to reload.</li>
<li><a href="https://github.com/dvajs/dva-docs/blob/master/v1/en-us/getting-started.md">Getting Started</a></li>
</ul>
</div>
<MainLayout location={location}>
<div className={styles.normal}>
<h1 className={styles.title}>Yay! Welcome to dva!</h1>
<div className={styles.welcome} />
<ul className={styles.list}>
<li>To get started, edit <code>src/index.js</code> and save to reload.</li>
<li><a href="https://github.com/dvajs/dva-docs/blob/master/v1/en-us/getting-started.md">Getting Started</a></li>
</ul>
</div>
</MainLayout>
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/routes/Users.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

.normal {
width: 900px;
margin: 3em auto 0;
}
11 changes: 7 additions & 4 deletions src/routes/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import React from 'react';
import { connect } from 'dva';
import styles from './Users.css';
import UsersComponent from '../components/Users/Users';
import MainLayout from '../components/MainLayout/MainLayout';

function Users() {
function Users({ location }) {
return (
<div className={styles.normal}>
<UsersComponent />
</div>
<MainLayout location={location}>
<div className={styles.normal}>
<UsersComponent />
</div>
</MainLayout>
);
}

Expand Down

0 comments on commit 404d040

Please sign in to comment.