Skip to content

Commit cfc5d62

Browse files
[go_router] Add documentation to some methods in matching.dart (flutter#3462)
[go_router] Add documentation to some methods in matching.dart
1 parent e4eb735 commit cfc5d62

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

packages/go_router/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Aligns Dart and Flutter SDK constraints.
44
- Updates compileSdkVersion to 33.
55
- Updates example app to iOS 11.
6+
- Updates documentation in matching methods.
67

78
## 6.2.0
89

packages/go_router/lib/src/matching.dart

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class RouteMatcher {
4848
}
4949

5050
/// The list of [RouteMatch] objects.
51+
///
52+
/// This corresponds to the GoRouter's history.
5153
class RouteMatchList {
5254
/// RouteMatchList constructor.
5355
RouteMatchList(List<RouteMatch> matches, this._uri, this.pathParameters)
@@ -58,6 +60,33 @@ class RouteMatchList {
5860
static RouteMatchList empty =
5961
RouteMatchList(<RouteMatch>[], Uri.parse(''), const <String, String>{});
6062

63+
/// Generates the full path (ex: `'/family/:fid/person/:pid'`) of a list of
64+
/// [RouteMatch].
65+
///
66+
/// This methods considers that [matches]'s elements verify the go route
67+
/// structure given to `GoRouter`. For example, if the routes structure is
68+
///
69+
/// ```dart
70+
/// GoRoute(
71+
/// path: '/a',
72+
/// routes: [
73+
/// GoRoute(
74+
/// path: 'b',
75+
/// routes: [
76+
/// GoRoute(
77+
/// path: 'c',
78+
/// ),
79+
/// ],
80+
/// ),
81+
/// ],
82+
/// ),
83+
/// ```
84+
///
85+
/// The [matches] must be the in same order of how GoRoutes are matched.
86+
///
87+
/// ```dart
88+
/// [RouteMatchA(), RouteMatchB(), RouteMatchC()]
89+
/// ```
6190
static String _generateFullPath(Iterable<RouteMatch> matches) {
6291
final StringBuffer buffer = StringBuffer();
6392
bool addsSlash = false;
@@ -77,7 +106,12 @@ class RouteMatchList {
77106
final List<RouteMatch> _matches;
78107

79108
/// the full path pattern that matches the uri.
80-
/// /family/:fid/person/:pid
109+
///
110+
/// For example:
111+
///
112+
/// ```dart
113+
/// '/family/:fid/person/:pid'
114+
/// ```
81115
final String fullpath;
82116

83117
/// Parameters for the matched route, URI-encoded.
@@ -159,6 +193,18 @@ class MatcherError extends Error {
159193
}
160194
}
161195

196+
/// Returns the list of `RouteMatch` corresponding to the given `loc`.
197+
///
198+
/// For example, for a given `loc` `/a/b/c/d`, this function will return the
199+
/// list of [RouteBase] `[GoRouteA(), GoRouterB(), GoRouteC(), GoRouterD()]`.
200+
///
201+
/// - [loc] is the complete URL to match (without the query parameters). For
202+
/// example, for the URL `/a/b?c=0`, [loc] will be `/a/b`.
203+
/// - [restLoc] is the remaining part of the URL to match while [parentSubloc]
204+
/// is the part of the URL that has already been matched. For examples, for
205+
/// the URL `/a/b/c/d`, at some point, [restLoc] would be `/c/d` and
206+
/// [parentSubloc] will be `/a/b`.
207+
/// - [routes] are the possible [RouteBase] to match to [restLoc].
162208
List<RouteMatch>? _getLocRouteRecursively({
163209
required String loc,
164210
required String restLoc,

0 commit comments

Comments
 (0)