king
2018-09-29 31573a0912c1971a9043b3f9294f643c7d60a2aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import Vue from 'vue'
import Router from 'vue-router'
import homeView from '@/views/homeView'
import login from '@/views/login'
import goodsView from '@/views/goodsView'
import goodsclassView from '@/views/goodsclassView'
import goodsdetailView from '@/views/goodsdetailView'
import commentView from '@/views/commentView'
import paymentView from '@/views/paymentView'
import shoppingcarView from '@/views/shoppingcarView'
import personalView from '@/views/personalView'
import orderView from '@/views/orderView'
import orderdetailView from '@/views/orderdetailView'
import serviceView from '@/views/serviceView'
import estimateView from '@/views/estimateView'
import aftersaleView from '@/views/aftersaleView'
import collectionView from '@/views/collectionView'
import privateView from '@/views/privateView'
import addressView from '@/views/addressView'
 
Vue.use(Router)
 
const router = new Router({
  routes: [
    {
      path: '/',
      redirect: '/home/',
      meta: {
        title: '首页'
      }
    },
    {
      path: '/home',
      name: 'home',
      component: homeView,
      meta: {
        title: '首页'
      }
    },
    {
      path: '/login/:view',
      name: 'login',
      component: login,
      meta: {
        title: '登录'
      }
    },
    {
      path: '/goodsclass',
      name: 'goodsclass',
      component: goodsclassView,
      meta: {
        title: '商品分类'
      }
    },
    {
      path: '/goods/:type/:header',
      name: 'goods',
      component: goodsView,
      meta: {
        title: '商品分类'
      }
    },
    {
      path: '/goodsdetail',
      name: 'goodsdetail',
      component: goodsdetailView,
      meta: {
        title: '商品详情'
      }
    },
    {
      path: '/comment',
      name: 'comment',
      component: commentView,
      meta: {
        title: '评论'
      }
    },
    {
      path: '/payment',
      name: 'payment',
      component: paymentView,
      meta: {
        title: '确认付款'
      }
    },
    {
      path: '/shoppingcar',
      name: 'shoppingcar',
      component: shoppingcarView,
      meta: {
        title: '购物车'
      }
    },
    {
      path: '/personal',
      name: 'personal',
      component: personalView,
      meta: {
        title: '个人中心'
      }
    },
    {
      path: '/order',
      name: 'order',
      component: orderView,
      meta: {
        title: '我的订单'
      }
    },
    {
      path: '/orderdetail',
      name: 'orderdetail',
      component: orderdetailView,
      meta: {
        title: '订单详情'
      }
    },
    {
      path: '/service',
      name: 'service',
      component: serviceView,
      meta: {
        title: '客服'
      }
    },
    {
      path: '/estimate',
      name: 'estimate',
      component: estimateView,
      meta: {
        title: '评价'
      }
    },
    {
      path: '/aftersale',
      name: 'aftersale',
      component: aftersaleView,
      meta: {
        title: '售后'
      }
    },
    {
      path: '/collection',
      name: 'collection',
      component: collectionView,
      meta: {
        title: '我的收藏'
      }
    },
    {
      path: '/private',
      name: 'private',
      component: privateView,
      meta: {
        title: '个人资料'
      }
    },
    {
      path: '/address',
      name: 'address',
      component: addressView,
      meta: {
        title: '我的收货地址'
      }
    }
  ]
})
// 路由切换时更新title
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})
// 路由切换时,视图滚动至顶部
router.afterEach(() => {
  window.scrollTo(0, 0)
})
 
export default router