Skip to content

fix(structure): implement removeParamNames so duplicate route detection works across different parameter names #1610

@lisa-assistant

Description

@lisa-assistant

Background

In packages/structure/src/model/RWRoute.ts, the hasPathCollision getter is responsible for generating the 'Duplicate Path' diagnostic. It uses a local helper function removeParamNames to normalize paths before comparing them:

function removeParamNames(p: string) {
  // TODO: implement
  // foo/{bar}/baz --> foo/{}/baz
  return p
}

The function is not implemented — it just returns p unchanged. This means that routes like:

  • /users/{id} and /users/{userId}
  • /posts/{id:Int} and /posts/{slug:String}

are not detected as path collisions, even though they would match the same URL patterns at runtime, causing ambiguous routing behavior.

What needs to be done

Implement removeParamNames to strip parameter names (and types) from path segments, so that two paths with the same structure but different parameter names are recognized as duplicates.

Fix:

function removeParamNames(p: string) {
  // foo/{bar}/baz --> foo/{}/baz
  // foo/{id:Int}/baz --> foo/{}/baz
  return p.replace(/\{[^}]+\}/g, '{}')
}

This regex replaces any {...} segment (including typed params like {id:Int}) with {}, normalizing the path for comparison.

File

packages/structure/src/model/RWRoute.ts, line 268–271

Impact

Without this fix, users can accidentally define two routes that match the same URL (e.g., <Route path="/post/{id}" ...> and <Route path="/post/{slug}" ...>) and the IDE/CLI diagnostic tool will not warn them. The router will silently use whichever route appears first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions