JSS: Alias Resolver
Aliases are not supported in JSS out-of-the-box. I'll show you how to set up a basic alias-resolver on your own.
In an ASP.NET MVC Sitecore solution, the alias resolvement takes place in the HttpRequestBegin-pipeline, via this processor: Sitecore.Pipelines.HttpRequest.AliasResolver, Sitecore.Kernel . This is not done for JSS however. I'm sure there are multiple ways you can solve this. I did it by creating my own ItemResolver.
JSS uses an ItemResolver-service to resolve the path that comes in via a LayoutService request into an actual Sitecore item. If you look at this ItemResolver in a decompiler (like DotPeek) you'll see that it does not resolve aliases at any point. So, I created an ItemResolver which inherits the OOB one.
Simply put, all it does is try to resolve the requested path as a simple item alias, before using the standard resolve method of the OOB resolver. If you decompile and look at the alias processor I mentioned at the top of this post, you'll see that it does a whole lot more. So feel free to extend the above code any which way you want.
The last thing you need to do in order to make the layout service use your ItemResolver is to replace the existing IItemResolver-service in the DI-container. You can do this like below:
And that's it. The layout service will now use your alias-resolving-item-resolver (...)!
27 May 2019, by Bonny Nilsson |
Sitecore 9, JSS 11, Aliases, LayoutService