Description
openedon Jul 2, 2020
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!