2024-04-26 06:23:50 +00:00
|
|
|
import { createRouter, createWebHashHistory } from 'vue-router'
|
2024-03-28 02:46:41 +00:00
|
|
|
|
|
|
|
import Login from '@/views/Login/index.vue'
|
|
|
|
import Exam from '@/views/Exam/index.vue'
|
2024-04-11 09:02:17 +00:00
|
|
|
import ScaleList from '@/views/ScaleList/index.vue'
|
2024-04-15 09:33:01 +00:00
|
|
|
import ExamDetail from '@/views/ExamDetail/index.vue'
|
2024-03-28 02:46:41 +00:00
|
|
|
|
|
|
|
const router = createRouter({
|
2024-07-02 06:32:15 +00:00
|
|
|
history: createWebHashHistory('/'),
|
2024-03-28 02:46:41 +00:00
|
|
|
routes: [
|
|
|
|
{
|
|
|
|
path: '/login',
|
|
|
|
component: Login
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/',
|
2024-04-11 09:02:17 +00:00
|
|
|
component: ScaleList
|
|
|
|
},
|
|
|
|
{
|
2024-04-12 06:47:28 +00:00
|
|
|
path: '/exam',
|
2024-03-28 02:46:41 +00:00
|
|
|
component: Exam
|
2024-04-16 08:36:38 +00:00
|
|
|
},
|
2024-04-15 09:33:01 +00:00
|
|
|
{
|
|
|
|
path:'/examDetail',
|
2024-04-16 08:36:38 +00:00
|
|
|
component: ExamDetail,
|
|
|
|
}
|
2024-03-28 02:46:41 +00:00
|
|
|
],
|
|
|
|
// 路由滚动行为定制
|
|
|
|
scrollBehavior() {
|
|
|
|
return {
|
|
|
|
top: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-04-11 09:02:17 +00:00
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
const token = localStorage.getItem('token')
|
|
|
|
if (to.path === '/login') {
|
|
|
|
next()
|
|
|
|
} else {
|
|
|
|
if (token) {
|
|
|
|
next()
|
|
|
|
} else {
|
|
|
|
next('/login')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2024-03-28 02:46:41 +00:00
|
|
|
export default router
|