react-helmet#HelmetProps TypeScript Examples
The following examples show how to use
react-helmet#HelmetProps.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Helmet.tsx From gatsby-plugin-react-i18next with MIT License | 6 votes |
Helmet: React.FC<HelmetProps> = ({children, ...props}) => {
const {languages, language, originalPath, defaultLanguage, siteUrl = ''} = useI18next();
const createUrlWithLang = (lng: string) => {
const url = `${siteUrl}${lng === defaultLanguage ? '' : `/${lng}`}${originalPath}`;
return url.endsWith('/') ? url : `${url}/`;
};
return (
<ReactHelmet {...props}>
<html lang={language} />
<link rel="canonical" href={createUrlWithLang(language)} />
{languages.map((lng) => (
<link rel="alternate" key={lng} href={createUrlWithLang(lng)} hrefLang={lng} />
))}
{/* adding a fallback page for unmatched languages */}
<link rel="alternate" href={createUrlWithLang(defaultLanguage)} hrefLang="x-default" />
{children}
</ReactHelmet>
);
}
Example #2
Source File: SEO.tsx From knboard with MIT License | 5 votes |
SEO = ({ title }: Pick<HelmetProps, "title">) => (
<Helmet title={title} titleTemplate="%s | Knboard" defaultTitle="Knboard" />
)