Skip to content

Commit

Permalink
Set hreflang on Link
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Nov 14, 2023
1 parent c7b2626 commit dc91509
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/next-intl/src/navigation/BaseLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ function BaseLink<Locales extends AllLocales>(
ref: Props<Locales>['ref']
) {
const defaultLocale = useLocale();
const linkLocale = locale || defaultLocale;
return (
<BaseLinkWithLocale ref={ref} locale={locale || defaultLocale} {...rest} />
<BaseLinkWithLocale
ref={ref}
hrefLang={linkLocale}
locale={linkLocale}
{...rest}
/>
);
}

Expand Down
7 changes: 7 additions & 0 deletions packages/next-intl/test/navigation/BaseLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ describe('unprefixed routing', () => {

expect(ref).toBeDefined();
});

it('sets an hreflang', () => {
render(<BaseLink href="/test">Test</BaseLink>);
expect(
screen.getByRole('link', {name: 'Test'}).getAttribute('hreflang')
).toBe('en');
});
});

describe('prefixed routing', () => {
Expand Down

0 comments on commit dc91509

Please sign in to comment.