diff --git a/starlette/routing.py b/starlette/routing.py index 9a2134957..90387f75d 100644 --- a/starlette/routing.py +++ b/starlette/routing.py @@ -421,9 +421,12 @@ def matches(self, scope: Scope) -> typing.Tuple[Match, Scope]: path = scope["path"] root_path = scope.get("route_root_path", scope.get("root_path", "")) route_path = scope.get("route_path", re.sub(r"^" + root_path, "", path)) - match = self.path_regex.match(route_path) - if match: - matched_params = match.groupdict() + mount_match = self.path_regex.match(route_path) + path_match = self.routes == [] or any( + [route.matches(scope)[0] == Match.FULL for route in self.routes] + ) + if mount_match and path_match: + matched_params = mount_match.groupdict() for key, value in matched_params.items(): matched_params[key] = self.param_convertors[key].convert(value) remaining_path = "/" + matched_params.pop("path")