Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor retrieve relative url

I am looking to retrieve the relative part of the current Blazor page URL.

For example if I am currently on https://www.mywebsite.com/someoverview, I wish to retrieve /someoverview.

like image 666
JeroenR Avatar asked Nov 09 '25 02:11

JeroenR


1 Answers

It's not Blazor specific, we have the Uri class:

var uri = new Uri(@"https://www.mywebsite.com/someoverview");
var relativePath = uri.LocalPath;  // or .PathAndQuery

or for the current Blazor page:

@inject NavigationManager Navigator

<a href="@Navigator.ToBaseRelativePath(Navigator.Uri)">here</a>

but do note that ToBaseRelativePath() does not include a leading /, it is different from LocalPath. You can mix & match.

like image 184
Henk Holterman Avatar answered Nov 11 '25 13:11

Henk Holterman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!