Skip to content

Conversation

erwan-legoff
Copy link
Contributor

The code was importing readItem from @directus/sdk but calling readItems, which caused a not found error. Replaced the import with readItems to ensure the method used is actually imported.
It fixes my error when coding.

The code was importing `readItem` from @directus/sdk but calling `readItems`, which caused a not found error.
Replaced the import with `readItems` to ensure the method used is actually imported.
@erwan-legoff erwan-legoff requested a review from a team as a code owner May 16, 2025 13:10
Copy link

vercel bot commented May 16, 2025

@erwan-legoff is attempting to deploy a commit to the Directus Team on Vercel.

A member of the Team first needs to authorize it.

@erwan-legoff
Copy link
Contributor Author

erwan-legoff commented May 16, 2025

After another try, this doesn't seem to work fine neither, always returning the first parge. But this worls :

import directus from '@/lib/directus';
import { notFound } from 'next/navigation';
import { readItems } from '@directus/sdk';

async function getPage(slug) {
    try {
        const pages = await directus.request(readItems('pages', {
            filter: { slug: { _eq: slug } },
        }));
        return pages[0];
    } catch (error) {
        notFound();
    }
}

export default async function DynamicPage({ params }) {
    const page = await getPage(params.slug);
    return (
        <div>
            <h1>{page.title}</h1>
            <div dangerouslySetInnerHTML={{ __html: page.content }}></div>
        </div>
    );
}

@rijkvanzanten rijkvanzanten merged commit de79a7b into directus:main Aug 4, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants