mirror of
https://gitee.com/novel_dev_team/novel-front-web
synced 2026-07-20 17:54:10 +08:00
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
import { createRouter, createWebHashHistory } from 'vue-router'
|
|
|
|
const router = createRouter({
|
|
// createWebHistory 路由模式路径不带#号(生产环境下不能直接访问项目,需要 nginx 转发)
|
|
// createWebHashHistory 路由模式路径带#号
|
|
history: createWebHashHistory(),
|
|
routes: [
|
|
{
|
|
path: '/',
|
|
redirect: '/home'
|
|
},
|
|
{
|
|
path: '/home',
|
|
name: 'home',
|
|
component: () => import('@/views/Home')
|
|
|
|
},
|
|
{
|
|
path: '/home',
|
|
name: 'newsContent',
|
|
component: () => import('@/views/Home')
|
|
},
|
|
{
|
|
path: '/book/:id',
|
|
name: 'book',
|
|
component: () => import('@/views/Book')
|
|
|
|
},
|
|
{
|
|
path: '/chapterList/:bookId',
|
|
name: 'chapterList',
|
|
component: () => import('@/views/BookChapterList')
|
|
|
|
},
|
|
{
|
|
path: '/book/:id/:chapterId',
|
|
name: 'bookContent',
|
|
component: () => import('@/views/BookContent')
|
|
|
|
}
|
|
]
|
|
})
|
|
|
|
// 解决 vue 中路由跳转时,总是从新页面中间开始显示
|
|
router.afterEach((to,from,next) => {
|
|
window.scrollTo(0,0)
|
|
})
|
|
|
|
export default router |