I am creating SPFX web part with React.

In which I am trying to get the current page ID on which webpart is added. I was trying to check if I can get it directly from the page context.

I am getting page context using this.context.pageContext but I noticed some of the properties are undefined.

like this.context.pageContext.list, this.context.pageContext.listItem, this.context.pageContext.page these are undefined.

Could any one please tell me the reason behind this. OR please guide me on how to get the ID of the page on which web part is added.

Thanks a lot.

1 Answer 1


Answering my own question as it might be useful for someone else.

I figured that these properties are undefined while working/debugging on workbench.

But when we package and deploye this web part on particulat page, we can access these properties.

Cheers :)

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.