I have build a webpart with SPFx and using following libraries

@microsoft/sp-core-library": "1.6.0
@microsoft/sp-lodash-subset": "1.6.0
@microsoft/sp-office-ui-fabric-core": "1.6.0
@microsoft/sp-webpart-base": "1.6.0
@pnp/common": "^1.2.2
@pnp/logging": "^1.2.2
@pnp/odata": "^1.2.2
@pnp/sp": "^1.2.2*
react": "15.6.2

In our solution there will be alot of sitecollection and all collection will have alot of sitepages. The webpart will dynamically feed itself on data depending on the sitecollection name and sitepage name.

For an example if i have a sitecollection called SiteCol1 and it have a sitepage called finance the webpart should feed itself based on the names. When navigating to SiteCol1 -> Finance.aspx the webpart will call an API with parameters SiteCol1 and Finance.

At the current state i have managed to get sitecollection name thru this code

 sp.web.get().then((item:any) => {

Unfortunately its not this simple to get the .aspx sitepage. Does anyone have any good solution to get the current .aspx sitepage name.

1 Answer 1


It is available in the context info object itself in the serverRequestPath property.

In your code, you can consume it as below:

var currentPageUrl = this.context.pageContext.site.serverRequestPath;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.