...
Code Block |
---|
|
services.AddLynicon(...)
.SetDiverter(new SpaDataDiverter()); |
If you wanted to have some routes which served pages via the conventional MVC system, and others which provided content to a SPA, this can be done by overriding the diversion strategy used for specific content types as below (do this in the ConfigureServices method):
Code Block |
---|
|
DataDiverter.Instance.Register(typeof(TheContentType), new SpaDiversionStrategy("Lynicon", "DualFrameEditor")); |
Once the routing has been set up on the server side, seamless content editing requires a number of things to be set up in the front end platform:
- In your router, intercept url changes and make a request to the new url via AJAX ensuring you set the Accept header to 'application/json'. The server side routing will, based on the header, serve you the content data associated with the url as JSON. Forward this to the component or templating system so that it can be embedded in the rendered page at the appropriate places.
- Lynicon allows site navigation by following links in the preview window, keeping the editor in sync with the new page. To enable this functionality in a SPA, add another interception to url changes in your router. Ideally for performance this should come before the interception in 1. This code should check whether the new url is different to the existing page url, and if it is send a request to the new url with the query string '$mode=ping' appended. This tests whether the content management system should show an editor for the new url. If so, we cannot manage routing within the SPA as the CMS code on the server needs to build a new editor for the new url. So if this request returns with a 200 and a text response 'OK' then in-SPA routing should be cancelled and the window.top.location.href set to the new url, causing the top frame to go back to the server to build a new page. 'window.top' is used here as when content editing, the preview page is shown in an iframe, but it is the whole container that needs its url changed.