Page Link Example Needed

Vote:
 

Hello,

I am trying to figure out how to use IPageRouteHelper to get the current url a block is on.  I was directed to the page below for PageLink, but the Example section is empty.  Does anyone have an example handy?

https://world.episerver.com/documentation/class-library/?documentId=cms/10/7D323675

#200581
Jan 16, 2019 19:45
Vote:
 

If you get the IPageRouteHelper service it has a property called ContentLink which is the current page's PageReference. You can then pass this is to the IUrlResolver GetUrl method

#200597
Jan 17, 2019 10:32
Vote:
 

Thanks!  Yeah, ended up with this.   

        public static PageData CurrentPage =>
            ServiceLocator.Current.GetInstance<IPageRouteHelper>().Page;

        public static string CurrentPageUrl => UrlResolver.Value.GetUrl(CurrentPage);
#200963
Jan 31, 2019 15:22
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.