November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
We have done something Similar and had to use Search and Navigation to Find the Page to serve full example here
public class CampaignRouter : IPartialRouter<InsightLandingPage, CampaignPage>
{
#if DEBUG
private readonly TimeSpan _cacheTimespan = new TimeSpan(0, 0, 0);
#else
private readonly TimeSpan _cacheTimespan = new TimeSpan(0, 30, 0);
#endif
private ContentReference _container;
private string _urlSegment;
public CampaignRouter()
{
var settings = ServiceLocator.Current.GetInstance<ISiteSettingsProvider>();
_container = settings.Current.InsightsContainer;
}
public object RoutePartial(InsightLandingPage content, SegmentContext segmentContext)
{
if (!content.ContentLink.CompareToIgnoreWorkID(_container))
{
return null;
}
var nextSegment = segmentContext.GetNextValue(segmentContext.RemainingPath);
var urlSegment = nextSegment.Next;
if (string.IsNullOrEmpty(urlSegment))
{
return null;
}
ArticleBasePage article = null;
var cacheKey = $"routing-insights-{urlSegment}";
var cache = ServiceLocator.Current.GetInstance<ICache<ArticleBasePage>>();
_urlSegment = urlSegment;
if (cache.IsExists(cacheKey))
{
article = cache.Get(cacheKey, GetArticleBasePage);
}
else
{
article = GetArticleBasePage();
if (article != null) cache.AddToCache(cacheKey, article, _cacheTimespan);
}
if (article != null)
{
segmentContext.RemainingPath = nextSegment.Remaining;
segmentContext.RoutedContentLink = article.ContentLink;
}
return article;
}
private ArticleBasePage GetArticleBasePage()
{
var urlSegment = _urlSegment;
ArticleBasePage article = null;
var searchContext = SearchClient.Instance
.Search<ArticleBasePage>(SearchClient.Instance.Settings.Languages.GetSupportedLanguage("en"))
.Filter(x => x.URLSegment.MatchCaseInsensitive(urlSegment))
.Filter(d => d.Ancestors().Match(_container.ID.ToString()))
.StaticallyCacheFor(this._cacheTimespan)
.Select(r => r.ContentLink);
var searchResults = searchContext.GetResult().FirstOrDefault();
if (!ContentReference.IsNullOrEmpty(searchResults))
{
var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
article = contentRepository.Get<ArticleBasePage>(searchResults);
}
return article;
}
public PartialRouteData GetPartialVirtualPath(
CampaignPage content,
string language,
RouteValueDictionary routeValues,
RequestContext requestContext)
{
var contentLink = requestContext.GetRouteValue("node", routeValues)
as ContentReference;
if (!content.ContentLink.CompareToIgnoreWorkID(contentLink))
{
return null;
}
if (PageEditing.PageIsInEditMode)
{
return null;
}
return new PartialRouteData
{
BasePathRoot = _container,
PartialVirtualPath = content.URLSegment
};
}
}
Hi team,
I'm working on partial route in purpose to remove a segment from an URL.
We have the following structure:
Landing Page → Container Page → Start Page → Standard Page → [other pages of type Standard Page]
I need for each page under the ContainerPage to hide its segment from URL.
Example: http://siteHost/landingPage/containerPage/startPage/standardPage1/standardPage2/
Expected to be: http://siteHost/landingPage/startPage/standardPage1/standardPage2/
(no containerPage segment)
There is a partial router, it inherits from
where BasePage is a base type for both page types - StartPage and StandardPage. Methods of that interface are implemented:
Router is registered. We get into partial router for pages like following:
http://siteHost/landingPage/containerPage/startPage
But for the page from example it is not working - we even don't get into the method.
Did I miss something in the solution?
Thanks in advance!