Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bricks/dart_frog_dev_server/__brick__/server.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions docs/docs/basics/routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,23 @@ Response onRequest(RequestContext context, String userId, String postId) {
}
```

## Wildcard Routes β™Ύ

Dart Frog supports wildcard routes. For example, if you create a file called `routes/posts/[...page].dart`, then it will be accessible at any path that starts with `/posts/`, with any number of levels, allowing it to called from `/posts/today`, `/posts/features/stared`, and so forth.

Routing parameters are forwarded to the `onRequest` method as seen below:

```dart
import 'package:dart_frog/dart_frog.dart';

Response onRequest(RequestContext context, String page) {
return Response(body: 'post page: $page');
}
```

```warning
Wildcard routes **must** be unique leaf routes on their route node, meaning that they need to be a file, and they need to be the only route in their folder.

## Route Conflicts πŸ’₯

When defining routes, it's possible to encounter route conflicts.
Expand All @@ -425,11 +442,13 @@ A route conflict occurs when more than one route handler resolves to the same en
For example, given the following file structure:

```

β”œβ”€β”€ routes
β”‚Β Β  β”œβ”€β”€ api
β”‚Β Β  β”‚Β Β  └── index.dart
β”‚Β Β  └── api.dart
```

````

Both `routes/api/index.dart` and `routes/api.dart` resolve the the `/api` endpoint.

Expand All @@ -439,7 +458,7 @@ When running the development server via `dart_frog dev`, Dart Frog will report r
[hotreload] - Application reloaded.

Route conflict detected. `routes/api.dart` and `routes/api/index.dart` both resolve to `/api`.
```
````

When generating a production build via `dart_frog build`, Dart Frog will report all detected route conflicts and fail the build if one or more route conflicts are detected.

Expand Down