Pnpjs: SitePages into the URL

Created on 13 Mar 2019  路  3Comments  路  Source: pnp/pnpjs

Thank you for reporting an issue, suggesting an enhancement, or asking a question. We appreciate your feedback - to help the team understand your
needs please complete the below template to ensure we have the details to help. Thanks!

Please check out the Docs to see if your question is already addressed there. This will help us ensure our documentation covers the most frequent questions.

Category

  • [ ] Enhancement
  • [ ] Bug
  • [X] Question
  • [ ] Documentation gap/issue

Version

Please specify what version of the library you are using: [ ]

Please specify what version(s) of SharePoint you are targeting: [ ]

If you are not using the latest release, please update and see if the issue is resolved before submitting an issue.

Expected / Desired Behavior / Question

If you are reporting an issue please describe the expected behavior. If you are suggesting an enhancement please
describe thoroughly the enhancement, how it can be achieved, and expected benefit. If you are asking a question, ask away!

Observed Behavior

If you are reporting an issue please describe the behavior you expected to occur when performing the action. If you are making a
suggestion or asking a question delete this section.

Steps to Reproduce

If you are reporting an issue please describe the steps to reproduce the bug in sufficient detail to allow testing. If you are making
a suggestion or asking a question delete this section.

Submission Guidelines

Delete this section after reading

  • All suggestions, questions and issues are welcome, please let us know what's on your mind.
  • Remember to include sufficient details and context.
  • Please check back occasionally on your issue as we may have follow up questions.
  • If you have multiple suggestions, questions, or bugs please submit them in seperate issues so we can track resolution.

Thank you for your feedback!

I am trying to user your @pnp/sp library in a SPFx webpart to get the current user.
In testing on the Workbench on the Hosted Server (SharePoint Online) this all works well..
When I have packaged the solution and deployed the webpart it is incorrectly including sitepages in the URL.

If I am using this incorrectly, could you let me know how I should get the current userId.

sp.site.rootWeb.currentUser.get().then(user => {
if (user) {
this.setState({userId: user.Id});
/* do other stuff here*/
}
});

Most helpful comment

Hi @AndrewCarterBreakwaterIT!

With SPFx, the context should be bound: https://pnp.github.io/pnpjs/documentation/getting-started/#using-pnpcommon-setup

All 3 comments

If you are reporting an issue please describe the expected behavior. If you are suggesting an enhancement please
describe thoroughly the enhancement, how it can be achieved, and expected benefit. If you are asking a question, ask away!

Hi @AndrewCarterBreakwaterIT!

With SPFx, the context should be bound: https://pnp.github.io/pnpjs/documentation/getting-started/#using-pnpcommon-setup

Many thanks.. I did honestly read that .. but I wasn't sure whether it was required.. added this to the TS file and re published.. all good

Was this page helpful?
0 / 5 - 0 ratings