Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
Next.js static and dynamic metadata not working
Post Flair (click to view more posts with a particular flair)
Post Body

I'm checking this document to add either static or dynamic metadata to my page. When I run the page in localhost I can't see the metadata in the head. If I add it directly using <meta>everything works as intended.

The sample code when trying to use it directly in index.js is:

    import Layout from "@/components/layout"

    export const metadata = {
      title: "Create Next App",
      description: "Generated by create next app",
    }

    export default function Home() {
      return (
        <Layout>
          <div>This is an example</div>
        </Layout>
      )
    }

Another issue I noticed is that if I tried to add the metadata in the layout.js file then I get the following error even though I'm not using the "use client" directive.

ou are attempting to export "metadata" from a component marked with "use client",
which is disallowed. Either remove the export, or the "use client" directive. Read
more: https://nextjs.org/docs/getting-started/react-essentials#the-use-client-directive

This is the layout.js code:

export const metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
}

export default function Layout({ children }) {
  return (
    <div>
      <p>This is a layout</p>
      {children}
    </div>
  )
}

The documentation also mentions the following:

Config-based Metadata: Export a static metadata object or a dynamic generateMetadata
function in a layout.js or page.js file.

What constitutes a layout file? Is it any file called layout.js? Is it dependant on its parent directory same as pages?

You can find a sample of the project here

Author
Account Strength
60%
Account Age
2 years
Verified Email
Yes
Verified Flair
No
Total Karma
1,751
Link Karma
88
Comment Karma
1,663
Profile updated: 19 hours ago
Posts updated: 2 weeks ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
11 months ago