71 lines
1.5 KiB
JavaScript
71 lines
1.5 KiB
JavaScript
import { createRouter, createWebHistory } from "vue-router";
|
|
import { shouldLogin } from "../store";
|
|
import { ref, watch } from "vue";
|
|
import TimetableView from "../views/TimetableView.vue";
|
|
import SubstitutionView from "../views/SubstitutionView.vue";
|
|
import HistoryView from "../views/HistoryView.vue";
|
|
import SettingsView from "../views/SettingsView.vue";
|
|
import LoginView from "../views/LoginView.vue";
|
|
import TokenView from "../views/TokenView.vue";
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
|
routes: [
|
|
{
|
|
path: "/",
|
|
redirect: "/timetable",
|
|
},
|
|
{
|
|
path: "/timetable",
|
|
name: "title.timetable",
|
|
component: TimetableView,
|
|
meta: {
|
|
dataView: true,
|
|
},
|
|
},
|
|
{
|
|
path: "/substitutions",
|
|
name: "title.substitutions",
|
|
component: SubstitutionView,
|
|
meta: {
|
|
dataView: true,
|
|
},
|
|
},
|
|
{
|
|
path: "/history",
|
|
name: "title.history",
|
|
component: HistoryView,
|
|
meta: {
|
|
dataView: true,
|
|
},
|
|
},
|
|
{
|
|
path: "/settings",
|
|
name: "title.settings",
|
|
component: SettingsView,
|
|
},
|
|
{
|
|
path: "/login",
|
|
name: "title.login",
|
|
component: LoginView,
|
|
},
|
|
{
|
|
path: "/token",
|
|
name: "title.token",
|
|
component: TokenView,
|
|
},
|
|
],
|
|
});
|
|
|
|
export let lastRoute = ref();
|
|
router.beforeEach((_to, from) => {
|
|
lastRoute.value = from;
|
|
return true;
|
|
});
|
|
|
|
watch(shouldLogin, (value) => {
|
|
if (value) router.push("/login");
|
|
});
|
|
|
|
export default router;
|