Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    Feb 21, 2019 @ 05:04
    Nathan Woulfe
    0

    Maintaining requested URL with virtual node route handling

    I'm trying to set up routing so that I can use route segments in place of a query string, to allow things like this:

    /news/{type}/{topic} - where topic is used to filter a search

    It's much more user-friendly than news?topic=value or news?person=name

    I've added the required route:

            routes.MapUmbracoRoute("NewsListRoute",
                "news/{type}/{filter}",
                new
                {
                    controller = "News",
                    action = "FilteredNews",
                    filter = UrlParameter.Optional
                },
                new NewsListRouteHandler(),
                new {
                    type = "^(about|featuring)$"
                });
    

    and the handler:

        protected override IPublishedContent FindContent(RequestContext request, UmbracoContext context)
        {
            return context.ContentCache.GetById(KnownDocumentId.NewsIndex);
        }
    

    That all works fine - the request is routed to the controller and returns the render model back to the client.

    BUT...

    The displayed URL changes from /news/about/thing to /news, which is the instance returned by the handler.

    How do I serve the node at /news at the custom route /news/{type}/{filter}?

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Feb 21, 2019 @ 22:56
    Nik
    0

    Hey Nathan,

    Not sure if it would work, but what about https://our.umbraco.com/packages/website-utilities/autoroutetemplate/

    Nik

  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    Feb 21, 2019 @ 23:13
    Nathan Woulfe
    0

    That looks like it does pretty much exactly what I need - wanted to avoid any backoffice setup, but won't lose sleep over it...

Please Sign in or register to post replies

Write your reply to:

Draft