import LoginPage from "@/pages/LoginPage.vue"; import DashboardPage from "@/pages/dashboard/DashboardPage.vue"; import GuestStartPage from "@/pages/start/GuestStartPage.vue"; import UKStartPage from "@/pages/start/UKStartPage.vue"; import VVStartPage from "@/pages/start/VVStartPage.vue"; import { handleAcceptLearningMentorInvitation, handleCourseSessionAsQueryParam, handleCurrentCourseSession, redirectToLoginIfRequired, updateLoggedIn, } from "@/router/guards"; import { addToHistory, setLastNavigationWasPush } from "@/router/history"; import { onboardingRedirect } from "@/router/onboarding"; import { createRouter, createWebHistory } from "vue-router"; import { ATTENDANCE_ROUTE, CERTIFICATES_ROUTE, COCKPIT_ROUTE, COMPETENCE_ROUTE, COMPETENCES_ROUTE, DOCUMENTS_ROUTE, PERSONAL_PROFILE_ROUTE, SELF_EVALUATION_ROUTE, SETTINGS_ROUTE, } from "./names"; const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), scrollBehavior(to, from, savedPosition) { if (savedPosition) { return savedPosition; } else { return { top: 0 }; } }, routes: [ { path: "/start", name: "start", component: GuestStartPage, meta: { public: true, }, }, { path: "/start/vv", component: VVStartPage, name: "vvStart", meta: { public: true, }, }, { path: "/start/uk", component: UKStartPage, name: "ukStart", meta: { public: true, }, }, { path: "/login-local", component: LoginPage, meta: { public: true, }, }, { path: "/", name: "home", component: DashboardPage, }, { path: "/dashboard/persons", component: () => import("@/pages/dashboard/DashboardPersonsPage.vue"), }, { path: "/dashboard/persons-competence", component: () => import("@/pages/dashboard/DashboardPersonsPage.vue"), props: { mode: "competenceMetrics" }, }, { path: "/dashboard/due-dates", component: () => import("@/pages/dashboard/DashboardDueDatesPage.vue"), }, { path: "/dashboard/cost/:courseSessionId", component: () => import("@/pages/dashboard/DashboardCostPage.vue"), props: true, }, { path: "/course/:courseSlug", props: true, children: [ { path: "media", component: () => import("@/pages/mediaLibrary/MediaLibraryParentPage.vue"), props: true, children: [ { path: "", component: () => import("@/pages/mediaLibrary/MediaLibraryIndexPage.vue"), props: true, }, { path: ":categorySlug", props: true, component: () => import("@/pages/mediaLibrary/MediaLibraryCategoryPage.vue"), }, { path: ":categorySlug/:contentSlug", props: true, component: () => import("@/pages/mediaLibrary/MediaLibraryContentPage.vue"), }, ], }, { path: "competence", component: () => import("@/pages/competence/CompetenceParentPage.vue"), children: [ { path: "", props: true, name: COMPETENCE_ROUTE, component: () => import("@/pages/competence/CompetenceIndexPage.vue"), }, { path: "certificates", name: CERTIFICATES_ROUTE, props: true, component: () => import("@/pages/competence/CompetenceCertificateListPage.vue"), }, { path: "certificates/:certificateSlug", props: true, component: () => import("@/pages/competence/CompetenceCertificateDetailPage.vue"), }, { name: SELF_EVALUATION_ROUTE, path: "self-evaluation-and-feedback", props: true, component: () => import("@/pages/competence/SelfEvaluationAndFeedbackPage.vue"), }, { path: "competences", name: COMPETENCES_ROUTE, props: true, component: () => import("@/pages/competence/ActionCompetenceListPage.vue"), }, ], }, { path: "learn", children: [ { path: "", props: true, component: () => import("../pages/learningPath/learningPathPage/LearningPathPage.vue"), }, { path: ":circleSlug", component: () => import("../pages/learningPath/circlePage/CirclePage.vue"), props: true, }, { path: ":circleSlug/evaluate/:learningUnitSlug", component: () => import( "../pages/learningPath/selfEvaluationPage/SelfEvaluationPage.vue" ), props: true, }, { path: ":circleSlug/:contentSlug", component: () => import( "../pages/learningPath/learningContentPage/LearningContentPage.vue" ), props: true, }, ], }, { path: "profile/:userId", component: () => import("@/pages/userProfile/UserProfilePage.vue"), props: true, children: [ { path: "learning-path", component: () => import("@/pages/userProfile/LearningPathProfilePage.vue"), props: true, name: "profileLearningPath", meta: { hideChrome: true, showCloseButton: true, }, }, { path: "competence", component: () => import("@/pages/userProfile/CompetenceProfilePage.vue"), props: true, name: "profileCompetence", meta: { hideChrome: true, showCloseButton: true, }, children: [ { path: "", name: "competenceMain", component: () => import( "@/components/selfEvaluationFeedback/SelfEvaluationAndFeedbackOverview.vue" ), }, { path: "evaluations", name: "competenceEvaluations", component: () => import( "@/components/selfEvaluationFeedback/SelfEvaluationAndFeedbackList.vue" ), }, { path: "certificates/:certificateSlug", name: "competenceCertificateDetail", props: true, component: () => import("@/pages/competence/CompetenceCertificateDetailPage.vue"), }, { path: "certificates", name: "competenceCertificates", component: () => import("@/pages/competence/CompetenceCertificateListPage.vue"), }, ], }, ], }, { path: "learning-mentor", component: () => import("@/pages/learningMentor/mentor/MentorIndexPage.vue"), name: "learningMentor", children: [ { path: "", component: () => import("@/pages/learningMentor/mentor/MentorParticipantsPage.vue"), name: "mentorsAndParticipants", }, { path: "tasks", component: () => import("@/pages/learningMentor/mentor/MentorOverviewPage.vue"), name: "learningMentorOverview", }, { path: "self-evaluation-feedback/:learningUnitId", component: () => import("@/pages/learningMentor/mentor/SelfEvaluationFeedbackPage.vue"), name: "mentorSelfEvaluationFeedback", props: true, }, { path: "details", component: () => import("@/pages/learningMentor/mentor/MentorDetailParentPage.vue"), children: [ { path: "praxis-assignments/:praxisAssignmentId", component: () => import( "@/pages/learningMentor/mentor/MentorPraxisAssignmentPage.vue" ), name: "learningMentorPraxisAssignments", props: true, }, { path: "self-evaluation-feedback-assignments/:learningUnitId", component: () => import( "@/pages/learningMentor/mentor/MentorSelfEvaluationFeedbackAssignmentPage.vue" ), name: "learningMentorSelfEvaluationFeedbackAssignments", props: true, }, ], }, ], }, { path: "assignment-evaluation/:assignmentId/:userId", component: () => import("@/pages/assignmentEvaluation/AssignmentEvaluationPage.vue"), props: true, }, { path: "cockpit", name: "cockpit", component: () => import("@/pages/cockpit/cockpitPage/CockpitExpertParentPage.vue"), props: true, children: [ { path: "", component: () => import("@/pages/cockpit/cockpitPage/CockpitExpertHomePage.vue"), name: COCKPIT_ROUTE, props: true, }, { path: "profile/:userId/:circleSlug", component: () => import("@/pages/cockpit/CockpitUserCirclePage.vue"), props: true, }, { path: "feedback/:circleId", component: () => import("@/pages/cockpit/FeedbackPage.vue"), props: true, }, { path: "assignment/:assignmentId", component: () => import("@/pages/cockpit/assignmentsPage/AssignmentsPage.vue"), props: true, }, { path: "attendance", component: () => import("@/pages/cockpit/attendanceCheckPage/AttendanceCheckPage.vue"), props: true, name: ATTENDANCE_ROUTE, }, { path: "documents", component: () => import("@/pages/cockpit/documentPage/DocumentPage.vue"), props: true, name: DOCUMENTS_ROUTE, }, ], }, ], }, { path: "/lernbegleitung/:courseId/invitation/:invitationId", component: () => import("@/pages/learningMentor/InvitationAcceptPage.vue"), props: true, beforeEnter: handleAcceptLearningMentorInvitation, meta: { // The login redirect is handled in the beforeEnter guard public: true, }, }, { path: "/statistic/:courseSlug", props: true, component: () => import("@/pages/dashboard/statistic/StatisticParentPage.vue"), children: [ { path: "attendance", props: true, component: () => import("@/pages/dashboard/statistic/AttendanceList.vue"), }, { path: "assignment", props: true, component: () => import("@/pages/dashboard/statistic/AssignmentList.vue"), }, { path: "competence", props: true, component: () => import("@/pages/dashboard/statistic/CompetenceList.vue"), }, { path: "feedback", props: true, component: () => import("@/pages/dashboard/statistic/FeedbackList.vue"), }, { path: "list", props: true, component: () => import("@/pages/dashboard/CourseListPage.vue"), }, ], }, { path: "/statistic/:agentRole/:courseSlug/assignment", props: true, component: () => import("@/pages/dashboard/agentAssignment/AgentAssignmentStatisticPage.vue"), }, { path: "/statistic/:agentRole/:courseSlug/assignment/:assignmentId", props: true, component: () => import("@/pages/dashboard/agentAssignment/AgentAssignmentDetailPage.vue"), }, { path: "/statistic/:agentRole/:courseSlug/competence-grade", props: true, component: () => import("@/pages/dashboard/agentAssignment/AgentCompetenceGradePage.vue"), }, { path: "/statistic/:agentRole/:courseSlug/competence-grade/:courseSessionId/:competenceCertificateId", props: true, component: () => import("@/pages/dashboard/agentAssignment/AgentCompetenceGradeDetailPage.vue"), }, { path: "/shop", component: () => import("@/pages/ShopPage.vue"), }, { path: "/messages", component: () => import("@/pages/MessagesPage.vue"), }, { path: "/profile", component: () => import("@/pages/personalProfile/PersonalProfilePage.vue"), name: PERSONAL_PROFILE_ROUTE, }, { path: "/settings", name: SETTINGS_ROUTE, component: () => import("@/pages/SettingsPage.vue"), }, { path: "/notifications", component: () => import("@/pages/NotificationsPage.vue"), }, { path: "/onboarding/:courseType", props: true, component: () => import("@/pages/onboarding/WizardBase.vue"), meta: { public: true, hideChrome: true, }, beforeEnter: onboardingRedirect, children: [ { path: "account/create", component: () => import("@/pages/onboarding/AccountSetup.vue"), name: "accountCreate", props: true, }, { path: "account/confirm", component: () => import("@/pages/onboarding/AccountConfirm.vue"), name: "accountConfirm", }, { path: "account/profile", component: () => import("@/pages/onboarding/AccountProfile.vue"), name: "accountProfile", }, { path: "account/complete", component: () => import("@/pages/onboarding/uk/SetupComplete.vue"), name: "setupComplete", }, { path: "account/course-profile", component: () => import("@/pages/onboarding/vv/AccountCourseProfile.vue"), name: "accountCourseProfile", props: true, }, { path: "checkout/address", component: () => import("@/pages/onboarding/vv/CheckoutAddress.vue"), name: "checkoutAddress", props: true, }, { path: "checkout/complete", component: () => import("@/pages/onboarding/vv/CheckoutComplete.vue"), name: "checkoutComplete", }, ], }, { path: "/styleguide", component: () => import("../pages/StyleGuidePage.vue"), meta: { public: true, }, }, { path: "/:pathMatch(.*)*", component: () => import("../pages/404Page.vue"), }, ], }); router.beforeEach(updateLoggedIn); router.beforeEach(redirectToLoginIfRequired); // register after login hooks router.beforeEach(async (to) => await handleCurrentCourseSession(to)); router.beforeEach(async (to) => await handleCourseSessionAsQueryParam(to)); // only unset the current course session in the after hook router.afterEach(async (to) => await handleCurrentCourseSession(to, { unset: true })); router.beforeEach(addToHistory); // Wrap router.replace to track when it's called const originalReplace = router.replace; router.replace = function (to) { setLastNavigationWasPush(false); return originalReplace.call(this, to); }; // Wrap router.push to track when it's called const originalPush = router.push; router.push = function (to) { setLastNavigationWasPush(true); return originalPush.call(this, to); }; export default router;