Repository navigation
Description
When trying to create components that use relative URLs in the href I am always directed back to the base url rather than relatively, e.g. base-url/page instead of base-url/other/things/page
I've tried href="page", href="./page" and "href="~/page" as I saw these suggested but the only thing I've found that works is to use a Navigation Manger to directly access the current URL and then add to this - but this feels over the top?
I originally thought it was because I was using a NavLink component but I am also getting it with simple anchor tags. So I think it is incorrect behaviour.
Additional context/further feature request
The context where this has come up is trying the build a subnav component that we can re-use across different subsites/contexts. This is why using an absolute path isn't an option.
The site has the structure:
base-url/sub-site/page/sub-page
So the subnavigation needs to be able to handle any previous url base-url/sub-site-A/page-B/, base-url/subsite-C/page-D etc. but it provides all the same suffixes across these various prefixes.
Simply capturing the current URL and adding to it then caused issues like base-url/sub-site/page/sub-page/sub-page
and trying to remove parts of the URL might work but gets complicated when I consider more complex routes like base-url/sub-site/page/sub-page/sub-sub-page/... so that's not extensible either
So far I have made a workaround by passing the required relative base URL to the subnav component through a cascading parameter, i.e. relativeBase = “base-url/sub-site/page/”, then basing all hrefs in the subnav off of this new base.
However this all seems like I am missing something or that this is harder than it needs to be. Could there potentially be a SubNavLink component which could handle this kind of functionality: matching on some portion of the URL or have some ability to pattern match on the URL?
Thanks!
Activity
mkArtakMSFT commentedon Jul 6, 2020
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
mkArtakMSFT commentedon Jul 6, 2020
Hi @Emma37. Just wanted to share some context here. The current behavior is by-design. However we did receive similar feedback in the past. We plan to revisit this issue when we will be planning for .NET 6 and see whether there is something we can do to help in this space.
Trapulo commentedon Apr 12, 2021
I also think that is not natural this behavior, and it creates some problem creating internal portable references...
Felix-CodingClimber commentedon Nov 12, 2023
This feature would help a lot with content generated from markdown. Almost all markdown parsers use relative links for footnote and header links.
GiovanniNova commentedon Feb 1, 2024
Any news on this? I'm on .NET 7.0 and NavigationManager.NavigateTo also displays this unnatural behaviour, afaik only URLs that start with a forward slash (/) should be treated as absolute
changingmission commentedon Feb 2, 2024
Same issue with SSR Blazor
alfattack commentedon Oct 29, 2024
Any updates on this?
nicholasyin commentedon Mar 23, 2025
As always, it's been ignored, even though so many developers think this design anti-intuitive and inconsistent with normal html knowledge.
oakad commentedon Aug 12, 2025
Not only this issue is counter intuitive, Google AI and some other web resources think that it works correctly, that is, relative paths are resolved relative to current page URI, thus misleading unlucky developers.
Official documentation mentions the "relative to the base URI" bit in regular print, easy to miss: https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.navigationmanager.navigateto?view=aspnetcore-9.0
This is quite bad, because not many people have the capacity to test each and every link in their application.
nicholasyin commentedon Aug 21, 2025
Don't ever expect this will change, because the current behavior has been there for generations of .NET. MS is impossible to revert the behavior as it will break all existing code.
oakad commentedon Aug 21, 2025
However, navigation manager could provide a helper, in a form of extension method or something like that. I, for one, ended up coding my own. A decent posix path helper will also be handy, we are forced to maintain custom ones, because
IO.Pathcannot be trusted for such things.