Is it possible to decouple the use of the LayoutService from all of the Routing code and use it independently? We are upgrading an AngularJS application to Angular and have incorporated JSS but are not yet ready to commit to new Angular routing so would just like to have the ability to get JSS/Sitecore data within our new components. I don't want to make changes to the code that could break us with future upgrades to the Sitecore JSS libraries.

Any suggestions would be much appreciated.

up vote 3 down vote accepted

Absolutely possible to use without routing. The layout service is a simple REST API at its core, and it does not care if it's invoked from a router or not.

The sample app's jss-context.service.ts shows the REST call being made. The sitecore-jss-angular package's LayoutService type uses the angular HttpClient to make the call.

If you think you'll need routing later, it may be easier in the long term to keep the router around and just use a single route for the moment.

JSS apps must support server-side rendering to be usable in the Experience Editor, which means your app will need to be TransferState-aware like the sample is. During SSR, the route data is passed into the renderView() function directly and is not acquired via REST.

  • So is the general answer here suggesting that implementing only the REST API (LayoutService) approach could hamper how users make changes to the site? (i.e. they will not be able to use the Experience Editor?) They would only be able to change Content Tree items in Sitecore? – Toby Nunn Nov 7 at 17:05
  • 1
    Without routing on the client, EE support can become significantly more difficult. Sitecore's server-side routing needs to be able to match the client-side routing defined in JS. If the app has only one 'page' then EE is fine without routing. But if it has multiple views, or authors can add views, you may need routing or other customizations to use EE effectively. – Kam Figy Nov 8 at 19:00

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.