dy-router

This commit is contained in:
zuiidea
2016-12-28 00:03:59 +08:00
parent 5c0a9c0e08
commit 6b108497cc
4 changed files with 80 additions and 32 deletions
+15 -7
View File
@@ -20,6 +20,8 @@ const getPathSet = function (menuArray, parentPath) {
}
getPathSet(menu)
console.log(pathSet)
function Bread({ location }) {
let pathNames = []
location.pathname.substr(1).split('/').map((item, key) => {
@@ -30,14 +32,20 @@ function Bread({ location }) {
}
})
const breads = pathNames.map((item, key) => {
return (
<Breadcrumb.Item key={key} {...((pathNames.length - 1 == key)||!pathSet[item].clickable)? '' : { href: '#' + pathSet[item].path }}>
{pathSet[item].icon
? <Icon type={pathSet[item].icon} />
: ''}
<span>{pathSet[item].name}</span>
if (item=='-'){
return <Breadcrumb.Item key={key}>
无
</Breadcrumb.Item>
)
}else {
return (
<Breadcrumb.Item key={key} {...((pathNames.length - 1 == key)||!pathSet[item].clickable)? '' : { href: '#' + pathSet[item].path }}>
{pathSet[item].icon
? <Icon type={pathSet[item].icon} />
: ''}
<span>{pathSet[item].name}</span>
</Breadcrumb.Item>
)
}
})
return (
+1 -2
View File
@@ -5,9 +5,8 @@ import dva from 'dva'
const app = dva()
// 2. Model
app.model(require('./models/app'))
app.model(require('./models/users'))
app.model(require('./models/dashboard'))
// 3. Router
app.router(require('./router'))
+51 -16
View File
@@ -1,21 +1,56 @@
import React from 'react'
import { Router, Route , IndexRedirect } from 'dva/router'
import {Router} from 'dva/router'
import App from './routes/app'
import Error from './routes/error'
import Dashboard from './routes/dashboard'
import Users from './routes/users'
import Ico from './routes/ui/ico'
export default function ({ history }) {
return (
<Router history={ history }>
<Route path="/" component={ App } >
<IndexRedirect to="/dashboard" />
<Route path="dashboard" component={ Dashboard }/>
<Route path="/users" component={ Users } />
<Route path="/ui/ico" component={Ico}/>
<Route path="*" component={ Error } />
</Route>
</Router>
)
export default function ({history, app}) {
const routes = [
{
path: '/',
component: App,
// IndexRoute:{
// component: Error,
// },
childRoutes: [
{
path: 'dashboard',
name: 'dashboard',
getComponent(nextState, cb) {
require.ensure([], require => {
app.model(require('./models/dashboard'))
cb(null, require('./routes/dashboard'))
})
}
}, {
path: 'users',
name: 'users',
getComponent(nextState, cb) {
require.ensure([], require => {
cb(null, require('./routes/ui/ico'))
})
}
}, {
path: 'ui/ico',
name: 'ui/ico',
getComponent(nextState, cb) {
require.ensure([], require => {
app.model(require('./models/users'))
cb(null, require('./routes/users'))
})
}
}, {
path: '*',
name: 'error',
getComponent(nextState, cb) {
require.ensure([], require => {
cb(null, require('./routes/error'))
})
}
}
]
}
]
return <Router history={history} routes={routes}/>
}
+13 -7
View File
@@ -22,7 +22,8 @@ const bodyStyle = {
}
}
function Dashboard({dashboard}) {
function Dashboard({dashboard,dispatch}) {
console.log({dashboard,dispatch});
const {weather, sales, quote, numbers, recentSales, comments, completed, browser, cpu, user} = dashboard
const numberCards = numbers.map((item, key) => <Col key={key} lg={6} md={12}>
<NumberCard {...item}/>
@@ -97,11 +98,16 @@ function Dashboard({dashboard}) {
}
Dashboard.propTypes = {
dashboard: PropTypes.object
weather: PropTypes.object,
sales: PropTypes.array,
quote: PropTypes.object,
numbers: PropTypes.array,
recentSales: PropTypes.array,
comments: PropTypes.array,
completed: PropTypes.array,
browser: PropTypes.array,
cpu: PropTypes.object,
user: PropTypes.object,
}
function mapStateToProps({dashboard}) {
return {dashboard}
}
export default connect(mapStateToProps)(Dashboard)
export default connect(({dashboard}) => ({dashboard}))(Dashboard)