mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-02 10:41:54 +02:00
🔎 Add canonical url (#800)
This commit is contained in:
parent
d08ed6d0f7
commit
a9cee458a9
1 changed files with 13 additions and 1 deletions
|
@ -11,6 +11,7 @@ import { NextPage } from "next";
|
|||
import { AppProps } from "next/app";
|
||||
import { Inter } from "next/font/google";
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import { appWithTranslation } from "next-i18next";
|
||||
import { DefaultSeo } from "next-seo";
|
||||
import React from "react";
|
||||
|
@ -34,6 +35,7 @@ type AppPropsWithLayout = AppProps<PageProps> & {
|
|||
};
|
||||
|
||||
const MyApp: NextPage<AppPropsWithLayout> = ({ Component, pageProps }) => {
|
||||
const router = useRouter();
|
||||
React.useEffect(() => {
|
||||
if (process.env.NEXT_PUBLIC_ENABLE_ANALYTICS) {
|
||||
// calling inject directly to avoid having this run for self-hosted instances
|
||||
|
@ -41,15 +43,25 @@ const MyApp: NextPage<AppPropsWithLayout> = ({ Component, pageProps }) => {
|
|||
}
|
||||
}, []);
|
||||
|
||||
const canonicalUrl = React.useMemo(() => {
|
||||
const path = router.pathname === "/" ? "" : router.pathname;
|
||||
if (router.locale === router.defaultLocale) {
|
||||
return absoluteUrl(path);
|
||||
} else {
|
||||
return absoluteUrl(`/${router.locale}${path}`);
|
||||
}
|
||||
}, [router.defaultLocale, router.locale, router.pathname]);
|
||||
|
||||
const getLayout = Component.getLayout ?? ((page) => page);
|
||||
|
||||
return (
|
||||
<LazyMotion features={domMax}>
|
||||
<DefaultSeo
|
||||
canonical={canonicalUrl}
|
||||
openGraph={{
|
||||
siteName: "Rallly",
|
||||
type: "website",
|
||||
url: absoluteUrl(),
|
||||
url: canonicalUrl,
|
||||
images: [
|
||||
{
|
||||
url: absoluteUrl("/og-image-1200.png"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue