mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-05 20:21:50 +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 { AppProps } from "next/app";
|
||||||
import { Inter } from "next/font/google";
|
import { Inter } from "next/font/google";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
import { appWithTranslation } from "next-i18next";
|
import { appWithTranslation } from "next-i18next";
|
||||||
import { DefaultSeo } from "next-seo";
|
import { DefaultSeo } from "next-seo";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
@ -34,6 +35,7 @@ type AppPropsWithLayout = AppProps<PageProps> & {
|
||||||
};
|
};
|
||||||
|
|
||||||
const MyApp: NextPage<AppPropsWithLayout> = ({ Component, pageProps }) => {
|
const MyApp: NextPage<AppPropsWithLayout> = ({ Component, pageProps }) => {
|
||||||
|
const router = useRouter();
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (process.env.NEXT_PUBLIC_ENABLE_ANALYTICS) {
|
if (process.env.NEXT_PUBLIC_ENABLE_ANALYTICS) {
|
||||||
// calling inject directly to avoid having this run for self-hosted instances
|
// 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);
|
const getLayout = Component.getLayout ?? ((page) => page);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LazyMotion features={domMax}>
|
<LazyMotion features={domMax}>
|
||||||
<DefaultSeo
|
<DefaultSeo
|
||||||
|
canonical={canonicalUrl}
|
||||||
openGraph={{
|
openGraph={{
|
||||||
siteName: "Rallly",
|
siteName: "Rallly",
|
||||||
type: "website",
|
type: "website",
|
||||||
url: absoluteUrl(),
|
url: canonicalUrl,
|
||||||
images: [
|
images: [
|
||||||
{
|
{
|
||||||
url: absoluteUrl("/og-image-1200.png"),
|
url: absoluteUrl("/og-image-1200.png"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue