Skip to content

Commit

Permalink
hashHistory to browserHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
pmg1989 committed Feb 25, 2017
1 parent a07b2a6 commit e033164
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
13 changes: 7 additions & 6 deletions package.json
Expand Up @@ -23,10 +23,11 @@
"babel-plugin-import": "^1.0.1",
"babel-plugin-transform-runtime": "^6.9.0",
"babel-runtime": "^6.9.2",
"dora": "0.3.x",
"dora-plugin-proxy": "^0.7.0",
"dora-plugin-webpack": "0.6.x",
"dora-plugin-webpack-hmr": "^0.1.0",
"dora": "^0.4.3",
"dora-plugin-browser-history": "^0.2.0",
"dora-plugin-proxy": "^0.8.5",
"dora-plugin-webpack": "^0.8.1",
"dora-plugin-webpack-hmr": "^0.2.1",
"eslint": "^2.13.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.8.1",
Expand All @@ -40,8 +41,8 @@
"watchjs": "^0.0.0"
},
"scripts": {
"start": "dora --plugins \"proxy,webpack,webpack-hmr\"",
"dev": "dora --plugins \"webpack,webpack-hmr\"",
"start": "dora --plugins \"proxy,webpack,webpack-hmr,browser-history?index=/src/index.html\"",
"dev": "dora --plugins \"webpack,webpack-hmr,browser-history?index=/src/index.html\"",
"lint": "eslint --fix --ext .js,.jsx src/components/layout",
"build": "atool-build"
},
Expand Down
4 changes: 2 additions & 2 deletions src/index.html
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Ant Design Admin</title>
<link rel="stylesheet" href="index.css" />
<link rel="stylesheet" href="/index.css" />
<link rel="icon" href="https://t.alipayobjects.com/images/T1QUBfXo4fXXXXXXXX.png" type="image/x-icon">
<!--[if lte IE 10]>
<script
Expand All @@ -16,7 +16,7 @@

<div id="root"></div>

<script src="index.js"></script>
<script src="/index.js"></script>
<script src="//at.alicdn.com/t/font_c4y7asse3q1cq5mi.js"></script>

</body>
Expand Down
10 changes: 7 additions & 3 deletions src/index.js
@@ -1,14 +1,18 @@
import './index.html'
import dva from 'dva'
import { browserHistory } from 'dva/router'

// 1. Initialize
const app = dva()
const app = dva({
history: browserHistory,
onError(error) {
console.error("app onError -- ", error)
}
})

// 2. Model

app.model(require('./models/app'))
app.model(require('./models/dashboard'))
app.model(require('./models/users'))

// 3. Router
app.router(require('./router'))
Expand Down
10 changes: 10 additions & 0 deletions src/router.js
Expand Up @@ -2,6 +2,14 @@ import React from 'react'
import {Router} from 'dva/router'
import App from './routes/app'

const cached = {};
function registerModel(app, model) {
if (!cached[model.namespace]) {
app.model(model)
cached[model.namespace] = 1
}
}

export default function ({history, app}) {
const routes = [
{
Expand All @@ -18,6 +26,7 @@ export default function ({history, app}) {
name: 'dashboard',
getComponent (nextState, cb) {
require.ensure([], require => {
registerModel(app, require('./models/dashboard'))
cb(null, require('./routes/dashboard'))
})
}
Expand All @@ -26,6 +35,7 @@ export default function ({history, app}) {
name: 'users',
getComponent (nextState, cb) {
require.ensure([], require => {
registerModel(app, require('./models/users'))
cb(null, require('./routes/users'))
})
}
Expand Down
7 changes: 7 additions & 0 deletions webpack.config.js
@@ -1,4 +1,5 @@
const webpack = require('atool-build/lib/webpack')
const path = require('path')

module.exports = function (webpackConfig, env) {
webpackConfig.babel.plugins.push('transform-runtime')
Expand All @@ -19,6 +20,12 @@ module.exports = function (webpackConfig, env) {
webpackConfig.babel.plugins.push('dev-expression')
}

webpackConfig.output = {
path: path.join(__dirname, '../dist'),
filename: '[name].js',
publicPath: '/'
}

// Don't extract common.js and common.css
webpackConfig.plugins = webpackConfig.plugins.filter(function (plugin) {
return !(plugin instanceof webpack.optimize.CommonsChunkPlugin)
Expand Down

0 comments on commit e033164

Please sign in to comment.