Getting a category from a URL

Hi

How can I get the category from a url? For example, lets say I want the SystemId for the tshirts category in www.example.com/clothes/tshirts.

I have been trying using the PageRouteResolver; but I am unsure what properties I need to set in routeRequestLookupInfo.

var x = _pageRouteResolver.TryGet(routeRequestLookupInfo, out RouteRequestInfo routeRequestInfo);

Litium version: 7.6.1

Maybe something like this:

var url = "example.com/clothes/tshirts";
var info = new RouteRequestLookupInfo()
{
	Channel = channel,
	Path = url,
	PathSegments = url.Split('/'),
};

_pageRouteResolver.TryGet(info, out var routeRequestInfo);

var categorySystemId = routeRequestInfo.Data is ProductPageData data ? data.CategorySystemId : Guid.Empty;
3 Likes

@NilsN That works as expected! Thanks!

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.