function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hector MariscalHector Mariscal 

How do you create a link to an external website in a lightning web component?

An <a> tag in the html file of the lwc is only adding the desired url to the current url of the community page that the lwc is in.
Best Answer chosen by Hector Mariscal
Raj VakatiRaj Vakati
A lightning-formatted-url component displays a text URL as a hyperlink with an href attribute. The valuecan be a relative or absolute URL. Absolute URLs use protocols such as http://, https://, and ftp://, followed by the domain name and path.

https://developer.salesforce.com/docs/component-library/bundle/lightning-formatted-url/example
<template>
    <p><lightning-formatted-url value="my/path" ></lightning-formatted-url></p>
    <p><lightning-formatted-url value="https://my/path" tooltip="Go to https://my/path" label="My Cool Website" target="_blank" ></lightning-formatted-url></p>
    <p><lightning-formatted-url value="ftp://my/path" tooltip="Go to ftp://my/path" ></lightning-formatted-url></p>
    <p><lightning-formatted-url value="http://my/path" ></lightning-formatted-url></p>
    <p><lightning-formatted-url value="/my/path" ></lightning-formatted-url></p>
    <p><lightning-formatted-url value=".my/path" ></lightning-formatted-url></p>
</template>

 

All Answers

Raj VakatiRaj Vakati
A lightning-formatted-url component displays a text URL as a hyperlink with an href attribute. The valuecan be a relative or absolute URL. Absolute URLs use protocols such as http://, https://, and ftp://, followed by the domain name and path.

https://developer.salesforce.com/docs/component-library/bundle/lightning-formatted-url/example
<template>
    <p><lightning-formatted-url value="my/path" ></lightning-formatted-url></p>
    <p><lightning-formatted-url value="https://my/path" tooltip="Go to https://my/path" label="My Cool Website" target="_blank" ></lightning-formatted-url></p>
    <p><lightning-formatted-url value="ftp://my/path" tooltip="Go to ftp://my/path" ></lightning-formatted-url></p>
    <p><lightning-formatted-url value="http://my/path" ></lightning-formatted-url></p>
    <p><lightning-formatted-url value="/my/path" ></lightning-formatted-url></p>
    <p><lightning-formatted-url value=".my/path" ></lightning-formatted-url></p>
</template>

 
This was selected as the best answer
Hector MariscalHector Mariscal
Thank you so much
Manish NagarManish Nagar
Hi Raj,
can tell me how to pass attributes in this link formatted.