Build Custom App Pages with SharePoint Framework

Overview

 
Single part app pages were recently introduced in Modern SharePoint. We can extend out of the box page templates by creating our own templates, however, they are limited to only that site. To use the page templates all across the tenant, we will have to create custom app pages using SharePoint framework. We can expose app pages by using new page template selection with SPFx web part on it.
 

Create SPFx Solution

 
Open the command prompt. Create a directory for SPFx solution.
  1. md single-part-app-page  
Navigate to the above-created directory.
  1. cd single-part-app-page  
Run the Yeoman SharePoint Generator to create the solution.
  1. yo @microsoft/sharepoint  
Yeoman generator will present you with the wizard by asking questions about the solution to be created.
 
Build Custom App Pages with SharePoint Framework
 
Solution Name: Hit Enter to have default name (single-part-app-page in this case) or type in any other name for your solution.
Selected choice: Hit Enter
 
Target for component: Here, we can select the target environment where we are planning to deploy the client web part, i.e., SharePoint Online or SharePoint OnPremise (SharePoint 2016 or 2019 onwards).
Selected choice: SharePoint Online only (latest)
 
Place of files: We may choose to use the same folder or create a subfolder for our solution.
Selected choice: Use the current folder
 
Deployment option: Selecting Y will allow the app to deployed instantly to all sites and will be accessible everywhere.
Selected choice: Y
 
Permissions to access web APIs: Choose if the components in the solution require permissions to access web APIs that are unique and not shared with other components in the tenant.
Selected choice: N (solution contains unique permissions)
 
Type of client-side component to create: We can choose to create a client-side web part or an extension.
Selected choice: WebPart, since single part app pages are web parts.
 
Web Part Name: Hit Enter to select the default name or type in any other name.
Selected choice: SinglePartPage
 
Web part description: Hit Enter to select the default description or type in any other value.
Selected choice: Hit Enter
 
Framework to use: Select any JavaScript framework to develop the component. Available choices are (No JavaScript Framework, React, and Knockout)
Selected choice: No JavaScript Framework
 
Yeoman generator will perform a scaffolding process to generate the solution. The scaffolding process will take a significant amount of time.
 
Once the scaffolding process is completed, lock down the version of project dependencies by running the below command.
  1. npm shrinkwrap  
In the command prompt, type the below command to open the solution in the code editor of your choice.
  1. code .  

Web Part Configuration

 
In order to expose this web part as a single part app page, we will have to make below configurations.
  1. Open SinglePartPageWebPart.manifest.json file under “\src\webparts\singlePartPage”.
  2. In the supportedHosts, add option SharePointFullPage.
Build Custom App Pages with SharePoint Framework
 
We will go ahead with the default implementation of the custom app page, without any customization to see how it looks out of the box.
 

Deploy the Package

 
Bundle the solution
 
On the command prompt, type the below command to bundle the solution.
  1. gulp bundle --ship  
Package the solution
 
On the command prompt, type below command to package the solution.
  1. gulp package-solution --ship  
Locate the single-part-app-page.sppkg file at “\single-part-app-page\sharepoint\solution”.
 
Add Package to App Catalog
  1. Open SharePoint Online App Catalog site.
  2. Add single-part-app-page.sppkg to app catalog.
  3. Select “Make this solution available to all sites in the organization”, as this custom app page should be available across the tenant.
  4. Click Deploy.
Build Custom App Pages with SharePoint Framework
 

Test the Custom App Page

 
  • Open Modern SharePoint site.
  • Click New > Page.
Build Custom App Pages with SharePoint Framework
  • The out of the box page templates are displayed. 
Build Custom App Pages with SharePoint Framework 
  • Click the Apps tab. The Apps tab is only displayed when custom app pages are deployed to the tenant.
  • Click our custom app, SinglePartPage. It displays the preview on the right side.
Build Custom App Pages with SharePoint Framework
  • Click Create page.
  • Specify the page title.
 
Build Custom App Pages with SharePoint Framework 
Our custom app page is now ready with our SPFx web part added to it.
 

Summary

 
We can extend out of the box page templates by creating our own templates, however, they are limited to only that site. To use the page templates all across the tenant, we will have to create custom app pages using SharePoint framework.