Skip to content

Commit f383344

Browse files
crswllyyx990803
authored andcommitted
Add an option for vue-router (vuejs-templates#415)
* adding a router option * don't turn on history mode automatically
1 parent e53a87c commit f383344

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

meta.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ module.exports = {
4040
}
4141
]
4242
},
43+
"router": {
44+
"type": "confirm",
45+
"message": "Install vue-router?"
46+
},
4347
"lint": {
4448
"type": "confirm",
4549
"message": "Use ESLint to lint your code?"
@@ -81,7 +85,8 @@ module.exports = {
8185
"config/test.env.js": "unit || e2e",
8286
"test/unit/**/*": "unit",
8387
"build/webpack.test.conf.js": "unit",
84-
"test/e2e/**/*": "e2e"
88+
"test/e2e/**/*": "e2e",
89+
"src/router/**/*": "router"
8590
},
8691
"completeMessage": "To get started:\n\n cd {{destDirName}}\n npm install\n npm run dev\n\nDocumentation can be found at https://vuejs-templates.github.io/webpack"
8792
};

template/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"lint": "eslint --ext .js,.vue src{{#unit}} test/unit/specs{{/unit}}{{#e2e}} test/e2e/specs{{/e2e}}"{{/lint}}
1414
},
1515
"dependencies": {
16-
"vue": "^2.1.10"
16+
"vue": "^2.1.10"{{#router}},
17+
"vue-router": "^2.1.1"{{/router}}
1718
},
1819
"devDependencies": {
1920
"autoprefixer": "^6.7.2",

template/src/App.vue

+8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
<template>
22
<div id="app">
33
<img src="./assets/logo.png">
4+
{{#router}}
5+
<router-view></router-view>
6+
{{else}}
47
<hello></hello>
8+
{{/router}}
59
</div>
610
</template>
711

812
<script>
13+
{{#unless router}}
914
import Hello from './components/Hello'{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
1015
16+
{{/unless}}
1117
export default {
1218
name: 'app',
19+
{{#unless router}}
1320
components: {
1421
Hello{{#if_eq lintConfig "airbnb"}},{{/if_eq}}
1522
}{{#if_eq lintConfig "airbnb"}},{{/if_eq}}
23+
{{/unless}}
1624
}{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
1725
</script>
1826

template/src/main.js

+7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
{{/if_eq}}
55
import Vue from 'vue'{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
66
import App from './App'{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
7+
{{#router}}
8+
9+
import router from './router'{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
10+
{{/router}}
711

812
/* eslint-disable no-new */
913
new Vue({
1014
el: '#app',
15+
{{#router}}
16+
router,
17+
{{/router}}
1118
{{#if_eq build "runtime"}}
1219
render: h => h(App){{#if_eq lintConfig "airbnb"}},{{/if_eq}}
1320
{{/if_eq}}

template/src/router/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Vue from 'vue'{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
2+
import Router from 'vue-router'{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
3+
4+
Vue.use(Router){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
5+
6+
import Hello from '../components/Hello'{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
7+
8+
export default new Router({
9+
routes: [
10+
{
11+
path: '/',
12+
name: 'Hello',
13+
component: Hello{{#if_eq lintConfig "airbnb"}},{{/if_eq}}
14+
}{{#if_eq lintConfig "airbnb"}},{{/if_eq}}
15+
]{{#if_eq lintConfig "airbnb"}},{{/if_eq}}
16+
}){{#if_eq lintConfig "airbnb"}};{{/if_eq}}

0 commit comments

Comments
 (0)