Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[JSS 21 - Latest] Anchor not handled correctly in Link component (sitecore-jss-react) #2115

@benten0101

Description

@benten0101

Describe the Bug

In the JSS Link component, anchor links don’t work when linktype is "anchor".

The current code:
const anchor = link.linktype !== 'anchor' && link.anchor ? #${link.anchor} : '';

So if linktype is "anchor", the # is never added even though the anchor value exists. Instead, the href ends up like /anchorname, which is treated as a path, not an in-page anchor.

To Reproduce

  1. Create a Link field in Sitecore with linktype: "anchor" and anchor: "my_anchor".
  2. Render it using in your JSS app.
  3. The output is instead of , so scrolling doesn't work.

{
"linktype": "anchor",
"href": "my_anchor",
"anchor": "my_anchor",
"text": "Go to Anchor"
}

Expected Behavior

If linktype === 'anchor' and an anchor value is present, the href should be #anchor, not /anchor.

Possible Fix

No response

Provide environment information

  • Sitecore Version: 10.4
  • JSS Version: 22.0.0
  • Browser Name and version: Google Chrome Version 138.0.7204.101 (Official Build) (64-bit)
  • Operating System and version (desktop or mobile): Windows Desktop

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions