From 7b5e678f39a1bba8a831c426edb0c114f47de89b Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Thu, 19 Jan 2023 11:30:20 -0600 Subject: [PATCH] docs(routes): include nested dynamic routes (#478) --- docs/docs/basics/routes.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/docs/basics/routes.md b/docs/docs/basics/routes.md index 635dfef79..c75d51891 100644 --- a/docs/docs/basics/routes.md +++ b/docs/docs/basics/routes.md @@ -350,7 +350,7 @@ Future onRequest(RequestContext context) async { ## Dynamic Routes 🌓 -Dart Frog supports dynamic routes. For example, if you create a file called `routes/posts/[id].dart`, then it will be accessible at `/posts/1`, `/posts/2`, etc. +Dart Frog supports dynamic routes. For example, if you create a file called `routes/posts/[id].dart`, then it will be accessible at `/posts/1`, `/posts/2`, and so on. Routing parameters are forwarded to the `onRequest` method as seen below. @@ -362,6 +362,16 @@ Response onRequest(RequestContext context, String id) { } ``` +Dart Frog also supports nested dynamic routes. For example, if you create a file called, `routes/users/[userId]/posts/[postId].dart`, then it will be accessible at `/users/alice/posts/1`, `/users/sam/posts/42`, and so on. + +Just as with all dynamic routes, routing parameters are forwarded to the `onRequest` method: + +```dart +Response onRequest(RequestContext context, String userId, String postId) { + return Response(body: 'user id: $userId, post id: $postId'); +} +``` + ## Route Conflicts 💥 When defining routes, it's possible to encounter route conflicts.