Thursday, 28 March 2019

How to detect the SharePoint Framework is running on modern or classic page using TS

SHARE


This below code sample shows how to detect the SharePoint current running  environment using typescript. The SharePoint Framework (SPFx) is a page and web part model that provides full support for client-side SharePoint development, easy integration with SharePoint data and support for open source tooling. Import this below namespace in your solution
Image result for sharepoint framework
Source:https://rencore.com/wp/wp-content/uploads/2018/03/framework-1.png

import { Environment, EnvironmentType } from '@microsoft/sp-core-library';

Include this below snippet in your Source code TS file
if(Environment.type == EnvironmentType.ClassicSharePoint){
    //do some stuff on classic page
}else if(Environment.type === EnvironmentType.SharePoint){
    //do some stuff on modern page
}else if(Environment.type === EnvironmentType.Local){
    //do some stuff on SharePoint workbench page
}


SHARE

Author: verified_user

0 Comments: