I have a fully functioning website but the head sections doesn't retrieve page specific <title>
and <meta description>
.
For example, if I'm on the about page, with the title tag "About me" I would like to have "About me" rendered in the <title>
tag. What I basically need is to load props, vars or something similar in my Head component that consist of an actual title and description. I've already read about some examples in the official documentation but there are no examples with updating the head with dynamic data.
This is the current code of my component:
import React from 'react';
import NextHead from 'next/head';
const Head = ({ title, description }) => (
<NextHead>
<meta charSet="UTF-8" />
<title>My Website{title}</title>
<meta name="description" content={description || ''} />
<meta name="viewport" content="width=device-width, initial-scale=1" key="viewport" />
</NextHead>
);
I've created a Layout.js component for the posts and pages. The <Head>
I described earlier is imported in the layout component.
import React from 'react';
import Head from '../components/Head';
export default ({ children, as, settings = {}, title="default text" }) => (
<main>
<Head>
<title>{title}</title>
</Head>
<div className="app__container">
<div className="row">{children}</div>
</div>
</main>
);
I expected that when I'm for example at /work/great-client I would see an updated <title>
tag with great-client