router.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import Vue from "vue";
  2. import Router from "vue-router";
  3. import NotFoundComponent from "./views/NotFoundComponent.vue";
  4. import OnlineExamHome from "./features/OnlineExam/OnlineExamHome.vue";
  5. import OnlineExamOverview from "./features/OnlineExam/OnlineExamOverview.vue";
  6. import ExamingHome from "./features/OnlineExam/Examing/ExamingHome.vue";
  7. import OfflineExamHome from "./features/OfflineExam/OfflineExamHome.vue";
  8. import OnlinePracticeHome from "./features/OnlinePractice/OnlinePracticeHome.vue";
  9. import Login from "./features/Login/Login.vue";
  10. import Password from "./features/Password/Password.vue";
  11. Vue.use(Router);
  12. let router = new Router({
  13. mode: "history",
  14. routes: [
  15. {
  16. path: "/",
  17. name: "Home",
  18. component: OnlineExamHome
  19. },
  20. {
  21. path: "/login",
  22. name: "Login",
  23. component: Login
  24. },
  25. {
  26. path: "/online-exam",
  27. name: "OnlineExamHome",
  28. component: OnlineExamHome
  29. },
  30. {
  31. path: "/online-exam/exam/:examId/overview",
  32. name: "OnlineExamOverview",
  33. component: OnlineExamOverview
  34. },
  35. {
  36. path:
  37. "/online-exam/exam/:examId/examRecordData/:examRecordDataId/order/:order",
  38. name: "OnlineExamingHome",
  39. component: ExamingHome
  40. },
  41. {
  42. path: "/online-practice",
  43. name: "OnlinePracticeHome",
  44. component: OnlinePracticeHome
  45. },
  46. {
  47. path: "/offline-exam",
  48. name: "OfflineExamHome",
  49. component: OfflineExamHome
  50. },
  51. {
  52. path: "/password",
  53. name: "Password",
  54. component: Password
  55. },
  56. {
  57. path: "*",
  58. component: NotFoundComponent
  59. }
  60. ]
  61. });
  62. router.beforeEach((to, from, next) => {
  63. if (to.path === "/login") {
  64. next();
  65. } else {
  66. if (!window.localStorage.getItem("token")) {
  67. next({ path: "/login" });
  68. } else {
  69. next();
  70. }
  71. }
  72. });
  73. export default router;