Skip to content

fix(router): treat /application as outside base="/app" - #572

Open
damiengrandi wants to merge 1 commit into
molefrog:v3from
damiengrandi:fix/base-prefix-boundary
Open

fix(router): treat /application as outside base="/app"#572
damiengrandi wants to merge 1 commit into
molefrog:v3from
damiengrandi:fix/base-prefix-boundary

Conversation

@damiengrandi

@damiengrandi damiengrandi commented Sep 13, 2026

Copy link
Copy Markdown

Description

Router with base="/app" treated /application as in-base (lication) because relativePath used a string prefix (indexOf === 0), not a path segment.

It now matches only when the path is the base, or continues with / / %2F (decodeURI leaves %2F encoded, so /app%2Fusers still yields %2Fusers).

To reproduce

Save as repro.mjs at the repo root, then run without this PR:

node repro.mjs

import { relativePath } from "./packages/wouter/src/paths.js";

const cases = [
  {
    base: "/app",
    path: "/app/users",
    expected: "/users",
    note: "real child of /app — should stay in-base",
  },
  {
    base: "/app",
    path: "/application",
    expected: "~/application",
    note: "different path that only shares the /app prefix",
  },
  {
    base: "/app",
    path: "/apple",
    expected: "~/apple",
    note: "same prefix collision",
  },
  {
    base: "/MyApp",
    path: "/MyOtherApp",
    expected: "~/MyOtherApp",
    note: "already OK — not a string prefix",
  },
];

for (const { base, path, expected, note } of cases) {
  const got = relativePath(base, path);
  const ok = got === expected;

  console.log(ok ? "ok  " : "FAIL");
  console.log(`  base=${base}  path=${path}`);
  console.log(`  expected ${JSON.stringify(expected)}`);
  console.log(`  got      ${JSON.stringify(got)}`);
  console.log(`  ${note}`);
  console.log("");
}

2/4 fail

To test the fix

  • Run bun test packages/wouter/test/path-normalization.test.tsx
  • Execute node repro.mjs again: no fail

Screenshots

bun test after the fix:

image

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant