Skip to content
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

Support mounting dynamic routes. FIxes #250 #288

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
update docstring
  • Loading branch information
davidmartos96 committed Sep 15, 2022
commit b75065c727a4e1ed8ef00f09e87684e86d72d16c
9 changes: 5 additions & 4 deletions pkgs/shelf_router/lib/src/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,18 @@ class Router {
Future<Response> _invokeMountedHandler(
Request request, Function handler, List<String> pathParams) async {
final paramsMap = request.params;
final effectivePath = _replaceParamsInPath(request.url.path, paramsMap);
final effectivePath = _getEffectiveMountPath(request.url.path, paramsMap);

return await Function.apply(handler, [
request.change(path: effectivePath),
...pathParams.map((param) => paramsMap[param]),
]) as Response;
}

/// Replaces the variable slots (<someVar>) from [path] with the
/// values from [paramsMap]
String _replaceParamsInPath(
/// Removes the "rest path" from the requested url in mounted routes. This
/// new path is then used to update the scope of the mounted handler with
/// [Request.change]
String _getEffectiveMountPath(
String urlPath,
Map<String, String> paramsMap,
) {
Expand Down