Overriding default routing

Vote:
 

I am trying to override default routing by implementing IPartialRouter and the RoutePartial method.  For the most part this works, however if the url that I make the request with matches the CMS hierarchy exactly, the RoutePartial method does not fire.  How do I go about preventing the Optimizely default routing from bypassing my custom router?

public class CustomRouter : IPartialRouter<PageData, PageData>
{
    public PartialRouteData GetPartialVirtualPath(PageData content, UrlGeneratorContext urlGeneratorContext)
    {
        return null;
    }

    public object RoutePartial(PageData content, UrlResolverContext segmentContext)
    {
        // This does not fire when url matches the CMS hierarchy
        // Example:
        //      URL: www.site.com/category/subcategory
        //      CMS: category -> subcategory

        var routedPage = content;
        segmentContext.RemainingSegments = ReadOnlyMemory<char>.Empty;
        segmentContext.Content = routedPage;

        var routeValues = HttpContextFactory.Current.GetRouteData();
        routeValues.Values.Add("test", "test");

        return routedPage;
    }
}
#336274
Jan 31, 2025 22:34
Vote:
 

You can't do that with partial routing, the docs sais "Partial routing lets you extend routing beyond pages. You can use partial routing to route to data outside Optimizely CMS or other content types other than pages.".

#336439
Feb 05, 2025 8:50
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.