Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Martin Soderlund Ek
Martin Soderlund Ek

Posted on

Partial Routing in Optimizely 12

If you need to implement partial routing in Optimizely CMS 12, this is a good start.

There are of course somebreaking changes as per the documentation:

The interface IPartialRouter changed slightly, and implementations should now be registered in DI container as IPartialRouter, rather than the previous way to register a partial router, which was through the extension method RegisterPartialRoute on RouteCollection.

OK, lets start with adding a partial router class which implements IPartialRouter:

public class MyPagePartialRouter : IPartialRouter<MyPage, MyPage>    {        public MyPagePartialRouter() { }        public object RoutePartial(MyPage content, UrlResolverContext urlResolverContext)        {            urlResolverContext.RouteValues.Add("requestPath", urlResolverContext.RemainingSegments);            urlResolverContext.RemainingSegments = Array.Empty<Char>();            return content;        }        public PartialRouteData GetPartialVirtualPath(MyPage content, UrlGeneratorContext urlGeneratorContext)        {            return null;        }    }
Enter fullscreen modeExit fullscreen mode

We add our params to theRouteValues collection. Note we useRemainingSegments instead of RemainingPath.

Then we need to register it in a DI container like this:

services.AddSingleton<IPartialRouter, MyPagePartialRouter>();

And that's it!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Full stack .NET developer, cyclist, father. Curious and happy!
  • Location
    Stockholm, Sweden
  • Joined

More fromMartin Soderlund Ek

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp