Skip to content

go_router_builder-v4.5.0

@brianegan brianegan tagged this 02 Sep 21:01
Adds build-time detection of routes that resolve to the same URL pattern. `go_router` matches the first route that fits, so a duplicated path silently makes the later route's page unreachable, and `LaterRoute().go(context)` navigates you to `EarlierRoute`'s page instead. Today nothing surfaces that until you run into the issue at runtime.

Reported as a warning by default, and  new `duplicate_route_paths` builder option accepts `warning` (the default), `error`, and `ignore`, so teams whose duplicates are mistakes can fail the build instead.

**Before**, `go_router_builder`'s own example app built clean despite two duplicate registrations:

```
$ dart run build_runner build
[INFO] Succeeded after 14s with 36 outputs
```

**After**:

```
$ dart run build_runner build
W go_router_builder on lib/all_types.dart:
  Duplicate route path detected: DoubleRoute is declared more than once at "double-route/:requiredDoubleField".
```

That duplicate was real. `DoubleRoute` had been registered twice since flutter/packages#2395 (2022) and `DoubleExtensionRoute` since flutter/packages#9458 (2025). Both were unreachable, and this PR removes them. The only change to the generated output is the dead route entries.

What competes for a URL namespace:

- Sibling routes, with path parameters normalized, so `product/:id` and `product/:productId` are one pattern.
- Routes inside shell routes and `StatefulShellRoute` branches, since those own no path of their own and their children compete with the routes around them.
- Relative routes, which own their path like any other route, so `/home/details/edit` and `/home/edit` stay distinct.
- Routes from separate annotations, since the generated `$appRoutes` collects them into one list. Scope is the library, `part` files included.

**Testing:** five new golden inputs in `test_inputs/` cover sibling duplicates, parameter-name-only differences, `StatefulShellRoute` branches, relative routes, cross-annotation duplicates, and the sound same-class grouping case. The golden harness gained two optional companion files per input, documented in the README: `<name>.dart.options` supplies JSON builder options so each severity is exercised through the real option-parsing path, and `<name>.dart.warnings` asserts logged warnings, with an empty file asserting silence.

Fixes flutter/flutter#190741

## Pre-Review Checklist

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Assets 2
Loading