+ 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