Scenario

You need to get the current site URL of a SharePoint site in SPFx. In JavaScript, we do it using _spPageContextInfo.webAbsoluteUrl. To do the same in SPFx we have to follow the below steps

Quick answer

Create a property in your webpart.ts file as shown below

siteUrl: this.context.pageContext.web.absoluteUrl

using this props, you can get the current site URL where your webpart is being rendered.