index.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * @Author: fxs bjnsfxs@163.com
  3. * @Date: 2024-08-20 14:06:49
  4. * @LastEditors: fxs bjnsfxs@163.com
  5. * @LastEditTime: 2024-10-10 17:35:00
  6. * @FilePath: \Game-Backstage-Management-System\src\router\index.ts
  7. * @Description:
  8. *
  9. */
  10. import { createRouter, createWebHashHistory } from 'vue-router'
  11. import { authLogin } from '@/utils/axios/auth'
  12. import HomeRoutes from './home'
  13. import LoginRoutes from './login'
  14. import AppManage from './appManage'
  15. const routes = [
  16. ...LoginRoutes,
  17. {
  18. path: '/index',
  19. name: 'Index',
  20. redirect: '/index/home/overView',
  21. component: () => import('@/views/Index.vue'),
  22. children: [...HomeRoutes, ...AppManage]
  23. },
  24. {
  25. path: '/',
  26. redirect: '/home/overView'
  27. },
  28. {
  29. //访问不存在的路由的时候,跳转到首页
  30. path: '/:pathMatch(.*)',
  31. redirect: '/home/overView'
  32. }
  33. ]
  34. const router = createRouter({
  35. history: createWebHashHistory(),
  36. routes
  37. })
  38. router.beforeEach((to, _from, next) => {
  39. if (to.name === 'Login') {
  40. next()
  41. } else {
  42. if (authLogin()) {
  43. next()
  44. } else {
  45. router.push('login')
  46. }
  47. }
  48. })
  49. export default router