初始化代码
This commit is contained in:
71
src/router/index.js
Normal file
71
src/router/index.js
Normal file
@ -0,0 +1,71 @@
|
||||
import {createWebHashHistory, createRouter} from 'vue-router'
|
||||
|
||||
import HomeView from '@/views/homepage/index.vue'
|
||||
|
||||
const routes = [
|
||||
{path: '/', component: HomeView},
|
||||
{
|
||||
path: '/product',
|
||||
component: () => import('@/views/product/index.vue'),
|
||||
meta: {
|
||||
title: '产品中心',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/services',
|
||||
component: () => import('@/views/services/index.vue'),
|
||||
meta: {
|
||||
title: '服务与支撑',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/news',
|
||||
component: () => import('@/views/news/index.vue'),
|
||||
meta: {
|
||||
title: '新闻中心',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/news/detail',
|
||||
name: 'Detail',
|
||||
component: () => import('@/views/news/detail.vue'),
|
||||
},
|
||||
{
|
||||
path: '/about',
|
||||
component: () => import('@/views/about/index.vue'),
|
||||
meta: {
|
||||
title: '关于我们',
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
path: '/link',
|
||||
component: () => import('@/views/link/index.vue'),
|
||||
meta: {
|
||||
title: '联系我们',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/download',
|
||||
component: () => import('@/views/download/index.vue'),
|
||||
meta: {
|
||||
title: '下载中心',
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes,
|
||||
})
|
||||
|
||||
router.afterEach((to, from) => {
|
||||
// 只有路径变化时才滚动到顶部
|
||||
if (to.path !== from.path) {
|
||||
requestAnimationFrame(() => {
|
||||
window.scrollTo({top: 0, behavior: 'instant'})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user