New Feature – SPAs embedded in SharePoint Online Modern Sites

Reading Time: 2 minutes

Much-awaited feature of the SharePoint Online users. Every one looking for the solution to load single web part  in full page. Now Microsoft published the solution.

Microsoft reference document here 

Single Page Web Part pages have following characters:

  • Single Part App Pages cannot be edited by end users using browser
  • Currently supports hosting only single web part or Microsoft Teams application
  • Page layout can only be changed programatically from normal page layout to a Single Page App Page
  • End-users cannot parametrize exposed web part or Teams application
  • Will we have an option to include the left menu?Yes – you will have the option to have left menu in the case of team sites.
  • Will it be possible to set an app page as the homepage? Yes

Steps to follow

  1. Create a new page
  2. Add a web part on the page
  3. Change the page layout type as SingleWebPartAppPage

Three ways to change the page layouts

  • Using developer tools and JavaScript

You can change existing page to use Single Page App Page layout by using browser developer tools. You can simply enable the developer tools and execute following code to change an existing page to use a SingleWebPartAppPage layout. You will need to adjust tenant and page name based on your environment in the below code…

var siteUrl = 'https://jpower4.sharepoint.com/sites/SinglePageApp/';
var pageUrl = 'SitePages/single-page.aspx';</pre>
fetch(siteUrl + '_api/contextinfo', {
method: 'POST',
headers: {
accept: 'application/json;odata=nometadata'
}
})
.then(function (response) {
return response.json();
})
.then(function (ctx) {
return fetch(siteUrl + "_api/web/getfilebyurl('" + pageUrl + "')/ListItemAllFields", {
method: 'POST',
headers: {
accept: 'application/json;odata=nometadata',
'X-HTTP-Method': 'MERGE',
'IF-MATCH': '*',
'X-RequestDigest': ctx.FormDigestValue,
'content-type': 'application/json;odata=nometadata',
},
body: JSON.stringify({
PageLayoutType: "SingleWebPartAppPage"
})
})
})
.then(function(res) {
console.log(res.ok ? 'DONE' : 'Error: ' + res.statusText);
});
<pre>
  • PnP Powershell

<span class="hljs-pscommand">Connect-PnPOnline</span><span class="hljs-parameter"> -Url</span> https://contoso.sharepoint.com/sites/marketing
<span class="hljs-variable">$item2</span> = <span class="hljs-pscommand">Get-PnPListItem</span><span class="hljs-parameter"> -List</span> <span class="hljs-string">"Site Pages"</span><span class="hljs-parameter"> -Query</span> <span class="hljs-string">"<View><Query><Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='Text'>page.aspx</Value></Eq></Where></Query></View>"</span>
<span class="hljs-variable">$item2</span>[<span class="hljs-string">"PageLayoutType"</span>] = <span class="hljs-string">"SingleWebPartAppPage"</span>
<span class="hljs-variable">$item2</span>.Update()
<span class="hljs-pscommand">Invoke-PnPQuery</span>

  • Office 365 CLI

o365 spo login https://jpower4.sharepoint.com/sites/SinglePageApp o365 spo listitem set –webUrl https://jpower4.sharepoint.com/sites/SinglePageApp –listTitle ‘Site Pages’ –id 3 –PageLayoutType SingleWebPartAppPage

Please share you feedback