Repository navigation
Open
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Fluttercustomer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.p: go_router_builderThe go_router_builder packageThe go_router_builder packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Description
Use case
It looks like with go_router_builder, you are supposed to define all your routes into this one gigantic file, this also leads to making two different classes that essentially represent the same thing, like a HomeRoute, and HomePage that you pass in the HomeRoutes build method. At this point the code generation only solves the compile time checking, and instead leaves you with even MORE boilerplate.
Proposal
We should be able to define route data in separate files.
Reacted by Kane Wickman, Rúben Ferreira, Valentin Vignal, Josh Huckabee, KoheiKanagu, Oleg Bezrukavnikov, Moritz Hartmann, mori yuta, Mohammed Musthafa, Daichi Fujita and 45 more
Reacted by Kane Wickman, Nick, Elias Pujols, Benji Farquhar, Enguerrand ARMINJON, Sheena and Bartosz
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Fluttercustomer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.p: go_router_builderThe go_router_builder packageThe go_router_builder packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Type
Projects
- StatusShow more project fieldsNo status
Activity
dancamdev commentedon Apr 8, 2023
I've given it a go, technically made it work but with a catch.
The only technical issue preventing us from having multiple definition files is that
go_router_buildergenerates a list always called$appRoutes.So, I went ahead and instead of it always being
$appRoutes, I've set the variable name to be based on the file name the generation is starting from.Therefore, given I have the following structure:
auth.dartpart ofauth.g.dartcontaining the/homeroute.unauth.dartpart ofunauth.g.dartcontaining/loginand/signuproutes.I can easily define the router as follows:
The drawback I see here, is that it being file based you could potentially end up with long and weird names. Such as:
Happy to discuss this further and open a PR with these changes if you want to take a deeper look into it.
lmapii commentedon Jun 1, 2023
I'm actually trying for the first time to use
go_route_builderand my first attempt was to attach the routes to the screens since this made most sense to me. I was surprised that I had to place all my route classes in the same file as the router.JasCodes commentedon Aug 24, 2023
This is one of the obious things that make me pull out hair. Forcing to put all routes in single file. Don't know who thought it was great idea.
Look at https://pub.dev/packages/katana_router how single AOP based can be...
vykes-mac commentedon Nov 9, 2023
@dancamdev Where did you set it so it generate the variable based on filename? Did you manually change the variable names? does it gets overwritten whenever you re-run the build_runner?
11 remaining items
mitryp commentedon Jul 7, 2025
Hello,
While we wait for the official implementation, I’ve developed go_router_aggregator to work around the current limitation. It gathers the generated
$appRoutesfrom across the project and combines them into one$aggregatedRoutescollection.You can already try it:
https://pub.dev/packages/go_router_aggregator
Feedback and contributions are very welcome on the package repository.
ManuelRauber commentedon Oct 15, 2025
Will there ever be an implementation for this? @chunhtai
It absolutely prevents using go_router with pub workspaces and a clear separation.
chunhtai commentedon Oct 15, 2025
I don't have any plan for this since I am currently helping with decoupling design library. If you want to work on this, feel free to submit a pr and pin me for review
[go_router_builder] Drop the two-team example, correct the file scope
[go_router_builder] Drop the two-team example, correct the file scope
[go_router_builder] Drop the two-team example, correct the file scope
[go_router_builder] Drop the two-team example, correct the file scope
[go_router_builder] Drop the two-team example, correct the file scope
[go_router_builder] Drop the two-team example, correct the file scope
[go_router_builder] Drop the two-team example, correct the file scope