title: Why is there a <base href="/" /> in Blazor's index.html or _Host.razor file?
body: <p>In every Blazor project, there is a <code>&lt;base href=&quot;/&quot;&gt;</code> inside of <code>index.html</code> or <code>_Host.razor</code> (depending on whether you're using Blazor WebAssembly or Blazor Server).</p>
  <p>Now, I know <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base" rel="noreferrer">what this tag does</a>, simply any value put inside of its <code>href</code> attribute would be prepended to every relative path in the HTML document.</p>
  <p>However, I don't understand why it's put there by default in every Blazor project. For example, if you're using Blazor WebAssembly, at the end of the <code>index.html</code> file there is this line:</p>
  <pre><code>&lt;script src=&quot;_framework/blazor.webassembly.js&quot;&gt;&lt;/script&gt;
  </code></pre>
  <p>There is obviously no <code>/</code> in the beginning of this path because a <code>&lt;base href=&quot;/&quot; /&gt;</code> is present in the document, but why couldn't they just simply add a leading <code>/</code> to this path so as to eliminate the need for the <code>base</code> tag altogether?! Why add the base tag?!</p>
  <p>I've also tried removing the <code>&lt;base href=&quot;/&quot; /&gt;</code> tag manually and instead added a leading <code>/</code> to all the paths, but then I quickly found out that doing so causes a problem:
  If you have a page that has a path like <code>/counter/something</code> (more than two levels), then the <code>blazor.webassembly.js</code> file, which after being loaded adds the other required JS files and assemblies to the HTML page dynamically, adds them without a leading slash and basically assumes that there is a <code>&lt;base href=&quot;/&quot; /&gt;</code>.</p>
  <p>For example, <code>blazor.webassembly.js</code> loads a file with this path &quot;_framework/blazor.boot.json&quot;. But in a scenario like the one I just explained, this would cause a 404 error as this is a relative path and there is no &quot;/counter/_framework/blazor.boot.json&quot;.</p>
  <p>So, this basically means that having a <code>&lt;base href=&quot;/&quot; /&gt;</code> is effectively mandatory in every Blazor application! But why?!</p>