private async Task <UmbracoRouteValues> SetPublishedContentAsOtherPageAsync(
        HttpContext httpContext, IPublishedRequest?publishedRequest, int pageId)
    {
        if (pageId != publishedRequest?.PublishedContent?.Id)
        {
            IUmbracoContext   umbracoContext   = _umbracoContextAccessor.GetRequiredUmbracoContext();
            IPublishedContent?publishedContent = umbracoContext.PublishedSnapshot.Content?.GetById(pageId);
            if (publishedContent is null || publishedRequest is null)
            {
                throw new InvalidOperationException("No content found by id " + pageId);
            }

            IPublishedRequest reRouted = await _publishedRouter.UpdateRequestAsync(publishedRequest, publishedContent);

            // we need to change the content item that is getting rendered so we have to re-create UmbracoRouteValues.
            UmbracoRouteValues updatedRouteValues = await _umbracoRouteValuesFactory.CreateAsync(httpContext, reRouted);

            return(updatedRouteValues);
        }

        throw new InvalidOperationException(
                  "Public Access rule has a redirect node set to itself, nothing can be routed.");
    }