Skip to content

Commit 3003a62

Browse files
committed
do not create localized path for pages in default language
Signed-off-by: Dmitriy Nevzorov <[email protected]>
1 parent 5ed17d2 commit 3003a62

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/Helmet.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ import {useI18next} from './useI18next';
44

55
export const Helmet: React.FC<HelmetProps> = ({children, ...props}) => {
66
const {languages, language, originalPath, defaultLanguage, siteUrl = ''} = useI18next();
7-
const createUrlWithLang = (lang: string) => {
8-
return `${siteUrl}${lang === defaultLanguage ? '' : `/${lang}`}${originalPath}`;
7+
const createUrlWithLang = (lng: string) => {
8+
return `${siteUrl}${lng === defaultLanguage ? '' : `/${lng}`}${originalPath}`;
99
};
1010
return (
1111
<ReactHelmet {...props}>
1212
<html lang={language} />
1313
<link rel="canonical" href={createUrlWithLang(language)} />
14-
{languages.map((lang) => (
15-
<link rel="alternate" key={lang} href={createUrlWithLang(lang)} hrefLang={lang} />
16-
))}
14+
{languages
15+
.filter((lng) => lng !== language)
16+
.map((lng) => (
17+
<link rel="alternate" key={lng} href={createUrlWithLang(lng)} hrefLang={lng} />
18+
))}
1719
{children}
1820
</ReactHelmet>
1921
);

src/plugin/onCreatePage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const onCreatePage = async (
6363
createPage(newPage);
6464

6565
await BP.map(languages, async (lng) => {
66+
if (lng === defaultLanguage) return;
6667
const localePage = await generatePage(lng, true);
6768
const regexp = new RegExp('/404/?$');
6869
if (regexp.test(localePage.path)) {

0 commit comments

Comments
 (0)