Skip to content

Feature Request: Support document.baseURI resolution #562

Description

@bensaufley

I have an application that is configured to deploy to a customizable base path (configured at runtime not build time), which is defined on the document using <base /> and accessible via document.baseURI. Because of this, ~ loses its utility and the base router's base value is tricky-at-best.

The URL class can be used to resolve these things but, at least so far, I haven't come up with a clean way to use Wouter's current functionality to support this use case. Is there a good way to do this today?

Proposed Behavior

What I would love is to be able to do something like this:

<Router base=".">{/* resolves under the hood to (new URL(document.baseURI).pathname) */}
  <Link href="/bat">Bat</Link>{/* Because this is under base=".", this becomes "./bat" -> <base>/bat */}
  <Link href="~/foo">Foo</Link>{/* links to <base>/foo from anywhere */}
  {/* OR, if we don't want to overload the ~ semantics: */}
  <Link href="./bar">Bar</Link>{/* pretty simple: new URL("./bar", document.baseURI), leaving: -> <base>/bar */}
  <Link href="~/bing">Bing</Link>{/* links to /foo from anywhere as it does today */}

Activity

  1. bensaufley commented on Apr 14, 2026

    @bensaufley
    ContributorAuthor

    Update: looks like <Link href="~./foo"> works for linking using the browser's internal mechanics, which is nice, so that just leaves the base resolution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions