Responsive Advertisement

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

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

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

Post a Comment