• AndyH

Reading the querystring


My web part needed to read a querystring. SharePoint Framework has a tool for that!


When I have created little chunks of JavaScript in the past and wanted to read the querystring, I needed to write my own code to get to the various parts easily. Fortunately there is a way to do this thanks to a useful blog post by Paul Matthews:

var querystring = new UrlQueryParameterCollection( window.location.href ); var id = querystring.getValue( "myId" );

This handy class lives in the Microsoft SP Core library, remember to add an import for it in your script:

import { UrlQueryParameterCollection } from '@microsoft/sp-core-library';
42 views

 

© 2019 AndyH  -  all rights reserved