Detecting SharePoint environment from an SPFX. SPFX web parts can be added to modern and classic SharePoint pages and we might need to load different resources depending of the environment type. The environment type can be detected using the EnvironmentType enumeration, directly from your SPFX code. Member Description ClasicSharePoint Indicates that the framework was loaded from a classic SharePoint page Local Indicates that the framework was loaded from the workbench SharePoint Indicates that the framework was loaded by a client-rendered SharePoint page Test Represents the scenario of the framework hosted in a unit/integration test To detect the environment type start by importing the enumeration from the sp-core-library: import { Environment, EnvironmentType} from '@microsoft/sp-core-library'; Use the code below to target...
Idea, Thought, Opinion, Feedback, Challenges, Experiences on Microsoft platform.