ptitlutins/app/composables/useNodeNav.ts
2026-06-15 23:34:49 +02:00

19 lines
752 B
TypeScript

import { parseNodePath, serializeNodePath } from "~/utils/nodePath"
/* Centralises the node-path URL scheme (?n=id.id). The focused-node path lives
* in the route query so navigation is real links (open-in-new-tab, back button)
* — components build `<NuxtLink :to>` targets through `linkTo`. The parse/build
* shape itself lives in `utils/nodePath` so the route middleware shares it. */
export const useNodeNav = () => {
const route = useRoute()
const currentPath = computed<string[]>(() => parseNodePath(route.query.n))
/** Route location for a given node path (empty path = the voyage root). */
const linkTo = (path: string[]) => ({
query: { ...route.query, n: serializeNodePath(path) },
})
return { currentPath, linkTo }
}