@@ -197,23 +197,32 @@ class Router {
197
197
Future <Response > _invokeMountedHandler (
198
198
Request request, Function handler, List <String > pathParams) async {
199
199
final paramsMap = request.params;
200
+ final effectivePath = _replaceParamsInPath (request.url.path, paramsMap);
200
201
202
+ return await Function .apply (handler, [
203
+ request.change (path: effectivePath),
204
+ ...pathParams.map ((param) => paramsMap[param]),
205
+ ]) as Response ;
206
+ }
207
+
208
+ /// Replaces the variable slots (<someVar>) from [path] with the
209
+ /// values from [paramsMap]
210
+ String _replaceParamsInPath (
211
+ String urlPath,
212
+ Map <String , String > paramsMap,
213
+ ) {
201
214
final pathParamSegment = paramsMap[_kRestPathParam];
202
- final urlPath = request.url.path;
203
215
late final String effectivePath;
204
216
if (pathParamSegment != null && pathParamSegment.isNotEmpty) {
205
217
/// If we encounter the "rest path" parameter we remove it
206
218
/// from the request path that shelf will handle.
207
219
effectivePath =
208
220
urlPath.substring (0 , urlPath.length - pathParamSegment.length);
209
221
} else {
222
+ // No parameters in the requested path
210
223
effectivePath = urlPath;
211
224
}
212
-
213
- return await Function .apply (handler, [
214
- request.change (path: effectivePath),
215
- ...pathParams.map ((param) => paramsMap[param]),
216
- ]) as Response ;
225
+ return effectivePath;
217
226
}
218
227
219
228
/// Route incoming requests to registered handlers.
0 commit comments