Fetch layout data with the JSS REST Layout Service
One of the endpoints you can use to get layout data from Sitecore is the Sitecore Layout Service provided by Sitecore Headless Services using theRestLayoutService class provided by JSS.
When using the Sitecore Layout Service, you can also enable (or disable) tracking of page views, by toggling the value for the tracking property of the JSS REST Layout Service.
To invoke the Sitecore Layout Service from a JSS application using the JSS :
-
In a
layout-service.tsfile, import theRestLayoutServiceclass and your app configuration: -
Create an instance of
RestLayoutServiceand provide the configuration object (of the typeRestLayoutServiceConfig): -
In the file where you want to fetch the data, import and use your new layout service instance:
If the default implementation does not meet your needs, you can use a custom data fetcher.