diff --git a/packages/sitecore-jss-nextjs/src/components/Link.test.tsx b/packages/sitecore-jss-nextjs/src/components/Link.test.tsx index 1383af08c1..735dfd0868 100644 --- a/packages/sitecore-jss-nextjs/src/components/Link.test.tsx +++ b/packages/sitecore-jss-nextjs/src/components/Link.test.tsx @@ -187,6 +187,22 @@ describe('', () => { expect(c.find(ReactLink).length).to.equal(0); }); + it('should not add extra hash when linktype is anchor', () => { + const field = { + linktype: 'anchor', + href: '#anchor', + text: 'anchor link', + anchor: 'anchor', + }; + const rendered = mount( + + + + ).find('a'); + expect(rendered.html()).to.contain(`href="${field.href}"`); + expect(rendered.text()).to.equal(field.text); + }); + it('should render NextLink using internalLinkMatcher', () => { const field = { value: { diff --git a/packages/sitecore-jss-react/src/components/Link.test.tsx b/packages/sitecore-jss-react/src/components/Link.test.tsx index 1468c7f22e..2e68362e32 100644 --- a/packages/sitecore-jss-react/src/components/Link.test.tsx +++ b/packages/sitecore-jss-react/src/components/Link.test.tsx @@ -4,6 +4,7 @@ import { mount } from 'enzyme'; import { Link, LinkField } from './Link'; import { generalLinkField as eeLinkData } from '../test-data/ee-data'; +import { it } from 'node:test'; describe('', () => { it('should render nothing with missing field', () => { @@ -51,6 +52,18 @@ describe('', () => { expect(rendered.html()).to.contain(field.text); }); + it('should not add extra hash when linktype is anchor', () => { + const field = { + linktype: 'anchor', + href: '#anchor', + text: 'anchor link', + anchor: 'anchor', + }; + const rendered = mount().find('a'); + expect(rendered.html()).to.contain(`href="${field.href}"`); + expect(rendered.text()).to.equal(field.text); + }); + it('should render ee HTML', () => { const field = { editableFirstPart: eeLinkData, diff --git a/packages/sitecore-jss-react/src/components/Link.tsx b/packages/sitecore-jss-react/src/components/Link.tsx index a0927b1cbe..5afdee6d53 100644 --- a/packages/sitecore-jss-react/src/components/Link.tsx +++ b/packages/sitecore-jss-react/src/components/Link.tsx @@ -12,6 +12,7 @@ export interface LinkFieldValue { text?: string; anchor?: string; querystring?: string; + linktype?: string; } export interface LinkField { @@ -95,7 +96,7 @@ export const Link = forwardRef( return null; } - const anchor = link.anchor ? `#${link.anchor}` : ''; + const anchor = link.linktype !== 'anchor' && link.anchor ? `#${link.anchor}` : ''; const querystring = link.querystring ? `?${link.querystring}` : ''; const anchorAttrs: { [attr: string]: unknown } = {