nextjs-corporate-starter
nextjs-corporate-starter copied to clipboard
[ PRs Welcome ] Error when fetching page data
I have followed all needed steps but I get this error.
wait - compiling...
event - compiled client and server successfully in 375 ms (265 modules)
wait - compiling /src/middleware (client and server)...
event - compiled successfully in 73 ms (73 modules)
wait - compiling /[lang]/page (client and server)...
event - compiled client and server successfully in 1303 ms (629 modules)
error - SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
error - SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
error - SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
error - SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
error - SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
error - src\app\[lang]\page.tsx (16:41) @ attributes
error - TypeError: Cannot read properties of undefined (reading 'attributes')
at RootRoute (./src/app/[lang]/page.tsx:28:42)
14 | export default async function RootRoute({ params }: { params: { lang: string } }) {
15 | const page = await getPageBySlug('home', params.lang);
> 16 | const contentSections = page.data[0].attributes.contentSections;
| ^
17 |
18 | return contentSections.map((section: any, index: number) => sectionRenderer(section, index));
19 | }
If I console log the page variable I get this:
{
data: [],
meta: { pagination: { page: 1, pageSize: 25, pageCount: 0, total: 0 } }
}
I noticed that params.lang will get value 'favicon.ico' but when request made with getPageBySlug('home', 'en');
I get correct data
{
data: [ { id: 1, attributes: [Object] } ],
meta: { pagination: { page: 1, pageSize: 25, pageCount: 1, total: 1 } }
}
But still there is this and nothing shows up at the browser
wait - compiling /[lang]/page (client and server)...
event - compiled successfully in 465 ms (276 modules)
error - SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
error - SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
error - SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)