Skip to content
This repository was archived by the owner on Nov 1, 2019. It is now read-only.

Commit b88a9b7

Browse files
committed
update: router, pages and layouts
1 parent 8ff7e80 commit b88a9b7

File tree

6 files changed

+141
-9
lines changed

6 files changed

+141
-9
lines changed

src/layouts/defaultLayout.vue

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<div class="defalut-layout">
3+
<h1>vue-template</h1>
4+
<router-view />
5+
</div>
6+
</template>
7+
8+
<script>
9+
export default {
10+
name: 'defalut-layout',
11+
data () {
12+
return {}
13+
}
14+
}
15+
</script>
16+
17+
<style lang="scss" scoped>
18+
.defalut-layout {
19+
text-align: center;
20+
}
21+
</style>

src/pages/About.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<div class="about">
3+
<h2>about</h2>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
name: 'about',
10+
data () {
11+
return {}
12+
}
13+
}
14+
</script>
15+
16+
<style lang="scss" scoped>
17+
</style>

src/pages/Err404.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<div class="err-404">
3+
<p>404</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
name: 'err-404',
10+
data () {
11+
return {
12+
}
13+
}
14+
}
15+
</script>
16+
17+
<style scoped>
18+
</style>

src/pages/Err500.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<div class="err-500">
3+
<p>500</p>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
name: 'err-500',
10+
data () {
11+
return {
12+
}
13+
}
14+
}
15+
</script>
16+
17+
<style scoped>
18+
</style>

src/pages/Home.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<div class="home">
3+
<h2>{{ msg }}</h2>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
name: 'home',
10+
data () {
11+
return {
12+
msg: 'Welcome to Your Vue.js App'
13+
}
14+
}
15+
}
16+
</script>
17+
18+
<style lang="scss" scoped>
19+
</style>

src/router/index.js

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,54 @@
11
import Vue from 'vue'
22
import Router from 'vue-router'
3-
import HelloWorld from '@/components/HelloWorld'
3+
4+
import defaultLayout from '@/layouts/defaultLayout'
5+
6+
import Home from '@/pages/Home'
7+
import About from '@/pages/About'
8+
import Err404 from '@/pages/Err404'
9+
import Err500 from '@/pages/Err500'
410

511
Vue.use(Router)
612

7-
export default new Router({
8-
routes: [
9-
{
10-
path: '/',
11-
name: 'HelloWorld',
12-
component: HelloWorld
13-
}
14-
]
13+
export const constantRouter = [
14+
{
15+
path: '/',
16+
component: defaultLayout,
17+
redirect: 'home',
18+
children: [
19+
{
20+
path: 'home',
21+
component: Home,
22+
name: 'home'
23+
},
24+
{
25+
path: 'about',
26+
component: About,
27+
name: 'about'
28+
}
29+
]
30+
},
31+
{
32+
path: '*',
33+
component: defaultLayout,
34+
redirect: 'err404',
35+
children: [
36+
{
37+
path: 'err404',
38+
component: Err404,
39+
name: 'err404'
40+
},
41+
{
42+
path: 'err500',
43+
component: Err500,
44+
name: 'err500'
45+
}
46+
]
47+
}
48+
]
49+
50+
const router = new Router({
51+
routes: constantRouter
1552
})
53+
54+
export default router

0 commit comments

Comments
 (0)