How to get the current site URL in SPFx

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.

Post a Comment

0 Comments