Search code examples
blazorblazor-webassembly

Can I have a NavLink with a relative URL


I have a WebAssembly Blazor app and I want the URLs in my menu to be relative to the current path. If I navigate to /demo/ and I click on a link with an href of games, I want it to navigate to /demo/games but instead, it treats the href as being absolute and navigates to /games.

Is there any way to achieve this. I don't want to have string fields for every link in the menu so that I can prefix every one with /demo/ individually in code.


Solution

  • You can add a <base> tag in your html head, which should give you control over the url's prefix:

    <head>
      <base href="/demo/" />
      ...
    </head>