router.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import Vue from "vue";
  2. import Router from "vue-router";
  3. import Home from "./views/Home.vue";
  4. import About from "./views/About.vue";
  5. import NotFoundComponent from "./views/NotFoundComponent.vue";
  6. import OnlineExamHome from "./features/OnlineExam/OnlineExamHome.vue";
  7. import Login from "./features/login/Login.vue";
  8. Vue.use(Router);
  9. let router = new Router({
  10. mode: "history",
  11. routes: [{
  12. path: "/",
  13. name: "home",
  14. component: Home
  15. },
  16. {
  17. path: "/about",
  18. name: "about",
  19. component: About
  20. },
  21. {
  22. path: "/login",
  23. name: "login",
  24. component: Login
  25. },
  26. {
  27. path: "/online-exam",
  28. name: "OnlineExamHome",
  29. component: OnlineExamHome
  30. },
  31. {
  32. path: "/online-exam",
  33. name: "OnlineExamHome",
  34. component: OnlineExamHome
  35. },
  36. {
  37. path: "*",
  38. component: NotFoundComponent
  39. }
  40. ]
  41. });
  42. router.beforeEach((to, from, next) => {
  43. debugger
  44. if (to.path === "/login") {
  45. next();
  46. } else {
  47. if (!window.localStorage.getItem("token")) {
  48. next({
  49. path: "/login"
  50. })
  51. } else {
  52. next();
  53. }
  54. }
  55. });
  56. export default router;