generated from pascalmartineau/wp-skeleton
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 59s
19 lines
746 B
TypeScript
19 lines
746 B
TypeScript
import type { ThePageFragment } from "#graphql-operations";
|
|
import { ThePage } from "#components";
|
|
|
|
export async function useNodeByUri() {
|
|
const route = useRoute();
|
|
const uri = computed(() => route.path);
|
|
const { data } = await useAsyncGraphqlQuery("nodeByUri", { uri: uri.value }, { graphqlCaching: { client: true } });
|
|
if (data.value?.errors?.length) {
|
|
throw createError({ statusCode: 500, message: "Erreur lors de la récupération du contenu", fatal: true });
|
|
}
|
|
const node = data.value?.data.nodeByUri;
|
|
switch (node?.__typename) {
|
|
case "Page":
|
|
return { component: ThePage, node: node as ThePageFragment };
|
|
default:
|
|
throw createError({ statusCode: 404, message: "Page non trouvée", fatal: true });
|
|
}
|
|
}
|