TypeScript functions to get current domain, site collection and Site urls with window.location fallback


Recently, I was working in a TypeScript project building a SPA application on top of Office 365 and I needed to get the current domain, current site collection and current site urls for using them in a different React components.

The case is we always rely on _spPageContextInfo to get this information, but in fact, we can use window.location object to build the urls as a fallback in case we need to use this Utils library before SP.js loaded or in other context.


Here is my solution for that problem using TypeScript:


Author: José Quinto
Link: https://blog.josequinto.com/2017/03/09/typescript-functions-to-get-current-domain-site-collection-and-site-urls-with-window-location-fallback/
Copyright Notice: All articles in this blog are licensed under CC BY-SA 4.0 unless stating additionally.