Don't route to main profile for child pages

This commit is contained in:
Christian Cueni 2024-08-04 19:14:56 +02:00
parent 41a0bbc22e
commit 9706d7a2f0
1 changed files with 18 additions and 5 deletions

View File

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref } from "vue"; import { onMounted } from "vue";
import { useRoute, useRouter } from "vue-router"; import { useRoute, useRouter } from "vue-router";
import { useTranslation } from "i18next-vue"; import { useTranslation } from "i18next-vue";
import { useFetch } from "@vueuse/core"; import { useFetch } from "@vueuse/core";
@ -12,18 +12,24 @@ const props = defineProps<{
const { t } = useTranslation(); const { t } = useTranslation();
const pages = ref([ const pages = [
{ {
label: t("general.learningPath"), label: t("general.learningPath"),
route: "profileLearningPath", route: "profileLearningPath",
routeMatch: "profileLearningPath", routeMatch: "profileLearningPath",
childrenRouteMatches: [],
}, },
{ {
label: t("a.KompetenzNavi"), label: t("a.KompetenzNavi"),
route: "competenceMain", route: "competenceMain",
routeMatch: "profileCompetence", routeMatch: "profileCompetence",
childrenRouteMatches: [
"competenceCertificates",
"competenceCertificateDetail",
"competenceEvaluations",
],
}, },
]); ];
const courseSession = useCurrentCourseSession(); const courseSession = useCurrentCourseSession();
const { data: user } = useFetch( const { data: user } = useFetch(
@ -35,9 +41,16 @@ const router = useRouter();
onMounted(() => { onMounted(() => {
// if current route name not in pages, redirect to first page // if current route name not in pages, redirect to first page
if (route.name && !pages.value.find((page) => page.route === route.name)) { if (
route.name &&
!pages.find((page) => {
const routeName = route.name?.toString() || "";
const routeMatch = [...page.childrenRouteMatches, page.routeMatch];
return routeMatch.some((match) => routeName.includes(match));
})
) {
router.push({ router.push({
name: pages.value[0].route, name: pages[0].route,
params: { userId: props.userId, courseSlug: props.courseSlug }, params: { userId: props.userId, courseSlug: props.courseSlug },
}); });
} }