app/
- head.tsx
- layout.tsx
- page.tsx
- blog/[slug]/page.tsx
Created
January 3, 2023 10:39
-
-
Save MakStashkevich/23e8059f3b018a3c6e8e811b1a2d59b9 to your computer and use it in GitHub Desktop.
Dynamic header title & meta tags on NextJs 13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
export default function RootHead() { | |
return undefined; // Disable root head | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import '../styles/globals.scss'; | |
export default function RootLayout({children}: { children: React.ReactNode }) { | |
return ( | |
<html> | |
<body> | |
{children} | |
</body> | |
</html> | |
) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
export default function RootPage() { | |
return ( | |
<div> | |
// Set title & description without <Head/> components | |
<title>Home</title> | |
<meta name="description" content="My homepage"/> | |
// Set page code | |
<p>Other staff...</p> | |
</div> | |
) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
async function getBlogData() { | |
return {title: "About me", description: "Read about me", content: "..."}; // Your blog content | |
} | |
export default async function BlogPage() { | |
const {title, description, content} = await getBlogData(); | |
return ( | |
<div> | |
// Set title & description without <Head/> components | |
<title>{title}</title> | |
<meta name="description" content={description}/> | |
// Set page content | |
<p>{content}</p> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
that's an example of dynamic metadata generated on the server for each movie id slug right after app router '/ home router'