SPFx: Click on anchor is not working as expected (event handler is not called)
I used the following code in my React project:
Ctor:
Method code:
Event binding
In the local workbench the event handling works perfectly but after I put the App on a regular modern SharePoint page the event was not handled. Instead the link was opened. During a debug session I found out that the event handler it not called! The reason: A CROSS SITE LINK :-(
When an anchor tag inside a SharePoint App contains a link to a different site the onClick event is not respected. To solve this issue you have to remove the href-Attribute or set the value to "#". Then the click-event is working as expected.
In case you want to keep the href-Attribute you can use the data attribute data-interception="off". This attribute managed the internal SharePoint page router logic. To disable the logic on a link set the attribute to OFF. For more information about the data attribute see: Hyperlinking considerations in SharePoint Framework
Happy coding :-)
Kommentare