Skip to content

Commit

Permalink
Update push and replace docs (tomgilder#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgilder authored Mar 13, 2022
1 parent ba5ac91 commit f3dec24
Showing 1 changed file with 43 additions and 30 deletions.
73 changes: 43 additions & 30 deletions lib/routemaster.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,14 @@ class Routemaster {
return _state.delegate.popUntil(predicate);
}

/// Replaces the current route with [path].
///
/// If the given [path] starts with a forward slash, it's treated as an
/// absolute path.
///
/// If it doesn't start with a forward slash, it's treated as a relative path
/// to the current route.
///
/// For example:
/// Replaces the current route with [path]. On the web, this prevents the user
/// returning to the previous route via the back button.
///
/// * If the current route is '/products' and you call `replace('1')`
/// you'll navigate to '/products/1'.
/// * [path] - an absolute or relative path. See [push] for the difference
/// between the two.
///
/// * If the current route is '/products' and you call `replace('/home')`
/// you'll navigate to '/home'.
/// * [queryParameters] - an optional map of string parameters to be passed
/// to the new route.
///
void replace(String path, {Map<String, String>? queryParameters}) {
final routeData = RouteData.maybeOf(_context);
Expand All @@ -205,21 +198,26 @@ class Routemaster {
_state.delegate.replace(path, queryParameters: queryParameters);
}

/// Pushes [path] into the navigation tree.
/// Navigates to [path].
///
/// If this path starts with a forward slash, it's treated as an absolute
/// path. Otherwise it's handled as a path relative to the current route.
///
/// For example, if the current route is '/products':
///
/// If the given [path] starts with a forward slash, it's treated as an
/// absolute path.
/// * Calling `push('1')` navigates to '/products/1'.
///
/// If it doesn't start with a forward slash, it's treated as a relative path
/// to the current route.
/// * Calling `push('/home')` navigates to '/home'.
///
/// For example:
/// A [queryParameters] map can be added to pass string parameters to the new
/// route:
///
/// * If the current route is '/products' and you call `replace('1')`
/// you'll navigate to '/products/1'.
/// `push('/search', queryParameters: {'query': 'hello'})`
///
/// * If the current route is '/products' and you call `replace('/home')`
/// you'll navigate to '/home'.
/// These can then be access from [RouteData], using
/// `RouteData.of(context).queryParameters`, or from within a route map:
///
/// `'/product': (route) => MaterialPage(child: SearchPage(route.queryParameters['id']))`
///
@optionalTypeArgs
NavigationResult<T> push<T extends Object?>(
Expand Down Expand Up @@ -400,12 +398,26 @@ class RoutemasterDelegate extends RouterDelegate<RouteData>
}
}

/// Pushes [path] into the navigation tree.
/// Navigates to [path].
///
/// If this path starts with a forward slash, it's treated as an absolute
/// path. Otherwise it's handled as a path relative to the current route.
///
/// For example, if the current route is '/products':
///
/// * Calling `push('1')` navigates to '/products/1'.
///
/// * Calling `push('/home')` navigates to '/home'.
///
/// A [queryParameters] map can be added to pass string parameters to the new
/// route:
///
/// `push('/search', queryParameters: {'query': 'hello'})`
///
/// * [path] - an absolute or relative path.
/// These can then be access from [RouteData], using
/// `RouteData.of(context).queryParameters`, or from within a route map:
///
/// * [queryParameters] - an optional map of parameters to be passed to the
/// created page.
/// `'/product': (route) => MaterialPage(child: SearchPage(route.queryParameters['id']))`
///
@optionalTypeArgs
NavigationResult<T> push<T extends Object?>(
Expand Down Expand Up @@ -443,10 +455,11 @@ class RoutemasterDelegate extends RouterDelegate<RouteData>
/// Replaces the current route with [path]. On the web, this prevents the user
/// returning to the previous route via the back button.
///
/// * [path] - an absolute or relative path.
/// * [path] - an absolute or relative path. See [push] for the difference
/// between the two.
///
/// * [queryParameters] - an optional map of parameters to be passed to the
/// created page.
/// * [queryParameters] - an optional map of string parameters to be passed
/// to the new route.
///
void replace(String path, {Map<String, String>? queryParameters}) {
assert(!_isDisposed);
Expand Down

0 comments on commit f3dec24

Please sign in to comment.