How to render <ContentDoc> and ignoring query parameters #1988
-
Hi, I have a problem: When ever I try to reach a dynamically routed page with query parameters, the server returns 404 page. Here's an example:
The page file is as follows:
And the [...slug].vue is as follows: <script setup>
const route = useRoute();
definePageMeta({
key: route => route.fullPath
})
const parkQuery = await queryContent({
where: {
_path: route.fullPath,
},
}).findOne();
// Capitalize city name for meta tags. City name = route.params.city
const city = route.params.city.charAt(0).toUpperCase() + route.params.city.slice(1);
if (parkQuery) {
useHead({
meta: [
{
name: "keywords",
content: `koirametsä ${parkQuery.title}, ${parkQuery.title}`,
},
{
name: "author",
content: "Koirametsät.info",
},
{
name: "robots",
content: "index, follow",
},
{
name: "googlebot",
content: "index, follow",
},
{
name: "og:title",
content: `${parkQuery.title} - ${city} - Koirametsät.info`,
},
{
name: "og:url",
content: `https://koirametsat.info${route.fullPath}`,
},
{
name: "description",
content: `${parkQuery.description} Koirametsän sijainti: ${city}.`,
},
{
name: "og:description",
content: `${parkQuery.description} Koirametsän sijainti: ${city}.`,
}
],
link: [
{
rel: "canonical",
href: `https://koirametsat.info${route.fullPath}`,
},
],
});
}
</script>
<template>
<ContentDoc/>
<SchemaOrgWebPage />
</template> This does not happen when on a strict route like Any help much appreciated. |
Beta Was this translation helpful? Give feedback.
Answered by
svirmasalo
Apr 4, 2023
Replies: 1 comment
-
Hi, This was the issue actualy: I used route.fullPath on a queryContent when I should have used route.path. <script setup>
const route = useRoute();
//....
const parkQuery = await queryContent({
where: {
_path: route.fullPath, // <-- Full path includes query params which caused the error. Use route.path instead.
},
}).findOne();
//... |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
svirmasalo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
This was the issue actualy:
I used route.fullPath on a queryContent when I should have used route.path.