Skip to content

[go_router] Add documentation to some methods in matching.dart #3462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 20, 2023
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
1 change: 1 addition & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Aligns Dart and Flutter SDK constraints.
- Updates compileSdkVersion to 33.
- Updates example app to iOS 11.
- Updates documentation in matching methods.

## 6.2.0

Expand Down
48 changes: 47 additions & 1 deletion packages/go_router/lib/src/matching.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class RouteMatcher {
}

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

/// Generates the full path (ex: `'/family/:fid/person/:pid'`) of a list of
/// [RouteMatch].
///
/// This methods considers that [matches]'s elements verify the go route
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe:

The [matches] must be the in same order of how GoRoutes are matched.

For example, if the routes structure is ...

/// structure given to `GoRouter`. For example, if the routes structure is
///
/// ```dart
/// GoRoute(
/// path: '/a',
/// routes: [
/// GoRoute(
/// path: 'b',
/// routes: [
/// GoRoute(
/// path: 'c',
/// ),
/// ],
/// ),
/// ],
/// ),
/// ```
///
/// The [matches] must be the in same order of how GoRoutes are matched.
///
/// ```dart
/// [RouteMatchA(), RouteMatchB(), RouteMatchC()]
/// ```
static String _generateFullPath(Iterable<RouteMatch> matches) {
final StringBuffer buffer = StringBuffer();
bool addsSlash = false;
Expand All @@ -77,7 +106,12 @@ class RouteMatchList {
final List<RouteMatch> _matches;

/// the full path pattern that matches the uri.
/// /family/:fid/person/:pid
///
/// For example:
///
/// ```dart
/// '/family/:fid/person/:pid'
/// ```
final String fullpath;

/// Parameters for the matched route, URI-encoded.
Expand Down Expand Up @@ -159,6 +193,18 @@ class MatcherError extends Error {
}
}

/// Returns the list of `RouteMatch` corresponding to the given `loc`.
///
/// For example, for a given `loc` `/a/b/c/d`, this function will return the
/// list of [RouteBase] `[GoRouteA(), GoRouterB(), GoRouteC(), GoRouterD()]`.
///
/// - [loc] is the complete URL to match (without the query parameters). For
/// example, for the URL `/a/b?c=0`, [loc] will be `/a/b`.
/// - [restLoc] is the remaining part of the URL to match while [parentSubloc]
/// is the part of the URL that has already been matched. For examples, for
/// the URL `/a/b/c/d`, at some point, [restLoc] would be `/c/d` and
/// [parentSubloc] will be `/a/b`.
/// - [routes] are the possible [RouteBase] to match to [restLoc].
List<RouteMatch>? _getLocRouteRecursively({
required String loc,
required String restLoc,
Expand Down