fix: await params Promise in blog and wiki [slug] pages for Next.js 16
- blog/[slug]/page.tsx: fix params type to Promise and await it - wiki/[slug]/page.tsx: fix params type to Promise and await it + Fix API port from 4000 to 4001 - blog/page.tsx: fix fallback API URL from port 4000 to 4001
This commit is contained in:
1 parent
3aebb9e176
commit
ab7ed279c8
5 files changed
+14
-10
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
@@ -24,8 +24,9 @@ async function getBlog(slug: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: { params: { slug: string } }): Promise<Metadata> {
|
||||
const blog = await getBlog(params.slug);
|
||||
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const blog = await getBlog(slug);
|
||||
if (!blog) return { title: 'مقاله یافت نشد' };
|
||||
|
||||
return {
|
||||
@@ -34,8 +35,9 @@ export async function generateMetadata({ params }: { params: { slug: string } })
|
||||
};
|
||||
}
|
||||
|
||||
export default async function BlogPostPage({ params }: { params: { slug: string } }) {
|
||||
const selectedPost = await getBlog(params.slug);
|
||||
export default async function BlogPostPage({ params }: { params: Promise<{ slug: string }> }) {
|
||||
const { slug } = await params;
|
||||
const selectedPost = await getBlog(slug);
|
||||
|
||||
if (!selectedPost) {
|
||||
return (
|
||||
|
||||
@@ -7,7 +7,7 @@ export const metadata: Metadata = {
|
||||
};
|
||||
|
||||
async function getBlogs() {
|
||||
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4000';
|
||||
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4001';
|
||||
try {
|
||||
const res = await fetch(`${apiUrl}/api/blogs`, { next: { revalidate: 60 } });
|
||||
if (!res.ok) throw new Error('Failed to fetch blogs');
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { Metadata } from 'next';
|
||||
|
||||
async function getBlog(slug: string) {
|
||||
try {
|
||||
const res = await fetch(`http://localhost:4000/api/blogs/${slug}`, { next: { revalidate: 60 } });
|
||||
const res = await fetch(`http://localhost:4001/api/blogs/${slug}`, { next: { revalidate: 60 } });
|
||||
if (!res.ok) throw new Error('Failed to fetch blog');
|
||||
return res.json();
|
||||
} catch (error) {
|
||||
@@ -13,8 +13,9 @@ async function getBlog(slug: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: { params: { slug: string } }): Promise<Metadata> {
|
||||
const blog = await getBlog(params.slug);
|
||||
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const blog = await getBlog(slug);
|
||||
if (!blog) return { title: 'مقاله یافت نشد' };
|
||||
|
||||
return {
|
||||
@@ -23,8 +24,9 @@ export async function generateMetadata({ params }: { params: { slug: string } })
|
||||
};
|
||||
}
|
||||
|
||||
export default async function BlogPage({ params }: { params: { slug: string } }) {
|
||||
const blog = await getBlog(params.slug);
|
||||
export default async function BlogPage({ params }: { params: Promise<{ slug: string }> }) {
|
||||
const { slug } = await params;
|
||||
const blog = await getBlog(slug);
|
||||
|
||||
if (!blog) {
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user