<script setup lang="ts">
// Resolve Node component from URI
const { path: uri } = useRoute();
const { data } = await useAsyncGraphQLQuery("NodeByUri", { uri });
if (!data.value?.nodeByUri) {
  throw createError({ statusCode: 404, message: `La page demandée est introuvable: ${uri}`, fatal: true });
}
const componentName = `Node${data.value.nodeByUri.__typename}`;
if (!useNuxtApp().vueApp.component(componentName)) {
  throw createError({ statusCode: 404, message: `La page demandée ne peut pas être affichée correctement: ${componentName}`, fatal: true });
}

useNodeSeo(data.value.nodeByUri);
</script>

<template>
  <div v-if="data?.nodeByUri" id="page-node-from-uri">
    <Component :is="componentName" v-bind="data.nodeByUri" />
  </div>
</template>
