-
Notifications
You must be signed in to change notification settings - Fork 174
Open
Labels
bugSomething isn't working as expectedSomething isn't working as expected
Description
Description
This report is from discord. Route conflict when static and dynamic routes overlap; static route should take precedence
Given routes:
- Static:
/bar - Dynamic:
/[foo]
Dart Frog CLI (v1.2.6) reports a route conflict when you run dart_frog dev or dart_frog build:
Route conflict detected. /<foo> and /bar both resolve to /<foo>.
Steps To Reproduce
-
create a [foo].dart in /routes
import 'package:dart_frog/dart_frog.dart'; Future<Response> onRequest(RequestContext context, String foo) async { // Simulate catch-all for any dynamic segment; return 404 for demonstration. return Response.json(statusCode: 404, body: { 'route': 'dynamic /[foo]', 'param': foo, 'message': 'not found (example)' }); }
-
create a bar.dart in /routes
import 'package:dart_frog/dart_frog.dart'; Response onRequest(RequestContext context) { return Response.json(body: {'route': 'static /bar'}); }
-
run
dart_frog devordart_frog build -
see the error
Route conflict detected. /<foo> and /bar both resolve to /<foo>.
Expected Behavior
There should be no route conflict. Static routes should take precedence over dynamic routes (similar to frameworks like Next.js). The dynamic route can act as a catch-all for all other values.
Next.js' doc:
Additional Context
If the dynamic part is not at the end, the error is reported differently.
e.g. /bar/baz and /<foo>/baz:
Route conflict detected. /bar/baz and /<foo>/baz both resolve to /bar/baz.
Route conflict detected. /<foo>/baz and /bar/baz both resolve to /<foo>/baz.
Metadata
Metadata
Assignees
Labels
bugSomething isn't working as expectedSomething isn't working as expected