I'm using the deufakt i18n localization plugin to translate a webpage, but I want to turn off localization for my /blog
route.
Basically what I want is this:
mypage.com/es/anotherRoute
-> mypage.com/blog
(The es
or any other language code goes away)
But that's not the main thing I want to achieve. The biggest problem is I'm not able to build the next app.
The error is basically that the post
in [slug]
is undefined when it's getting prerendered. Although it shouldn't be, because if I console.log it, it's there.
[slug]
import ErrorPage from "next/error";
import { getStrapiURL, getPageData, getBlogPost } from "utils/api";
import Sections from "@/components/sections";
import Seo from "@/components/elements/seo";
import { useRouter } from "next/dist/client/router";
import BlogPost from "@/components/blog/blogPost";
const BlogPage = ({ post, allPosts }) => {
const router = useRouter();
if (router.isFallback) {
return <div className="container">Loading...</div>;
}
return (
<>
{/* Add meta tags for SEO*/}
<Seo metadata={post.metadata} />
{/* Display content sections */}
<BlogPost {...{ post, allPosts }} />
</>
);
};
export async function getStaticPaths() {
const blogPosts = await (await fetch(getStrapiURL("/blog-posts"))).json();
const paths = blogPosts.map((page) => {
return {
params: { slug: page.slug },
};
});
return { paths, fallback: true };
}
export async function getStaticProps({ params, preview = null }) {
const pageData = await getBlogPost(params.slug);
const allPosts = await (await fetch(getStrapiURL("/blog-posts"))).json();
if (pageData == null) {
// Giving the page no props will trigger a 404 page
return { props: {} };
}
return {
props: {
post: pageData,
allPosts,
},
revalidate: 1,
};
}
export default BlogPage;
My pages
folder:
pages
├── [[...slug]].js
├── _app.js
├── _document.js
└── blog
├── [slug].js
└── index.js