Skip to content

Commit

Permalink
Fix reactivity in Breadcrumb
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Sep 18, 2023
1 parent 2edc47a commit 89f284d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
23 changes: 6 additions & 17 deletions src/Breadcrumb.vue
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
<script setup>
import { ref, watch } from "vue";
import { computed } from "vue";
import { useRoute, useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
import usePageTitle from "./title.composable";
const route = useRoute();
const { resolve } = useRouter();
const { getTitle } = usePageTitle();
const { t, locale } = useI18n();
const crumbs = ref([]);
/** Get a list of parent paths of the specified path, e.g. ["/", "/foo", "/foo/bar"] */
function getInits(path) {
const inits = [];
for (const seg of path.split("/").filter(Boolean)) {
const prevInit = inits[inits.length - 1] || "";
inits.push(prevInit + "/" + seg);
}
return inits;
return ["/", ...inits];
}
function updateCrumbs() {
const homeCrumb = { path: "/", title: t("home") };
crumbs.value = getInits(route.path)
const crumbs = computed(() =>
getInits(route.path)
.map((path) => {
const route = resolve(path);
return { path, title: getTitle(route), name: route.name };
})
.filter((crumb) => crumb.name != "notfound" && crumb.title);
crumbs.value.unshift(homeCrumb);
}
watch(
() => route.path,
() => updateCrumbs()
.filter((crumb) => crumb.name != "notfound" && crumb.title)
);
watch(locale, () => updateCrumbs());
</script>

<template>
Expand Down
8 changes: 7 additions & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import AccessDenied from "@/auth/AccessDenied.vue";
import NotFound from "@/NotFound.vue";

const routes = [
{ path: "/", component: Home },
{
path: "/",
component: Home,
meta: {
title: "home",
},
},
{
path: "/corpus",
component: Dashboard,
Expand Down

0 comments on commit 89f284d

Please sign in to comment.