diff --git a/fastapi/routing.py b/fastapi/routing.py index f3c5026dc..8fdee2c8e 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -1550,8 +1550,8 @@ class APIRouter(routing.Router): prefix + route.path, route.endpoint, name=route.name ) elif isinstance(route, routing.Mount): - self.mount(prefix + route.path, route.app, route.name) - + self.mount(prefix + router.prefix + route.path, route.app, name=route.name) + for handler in router.on_startup: self.add_event_handler("startup", handler) for handler in router.on_shutdown: diff --git a/tests/test_router_mount.py b/tests/test_router_mount.py index 57dbdd3e6..9bee074f4 100644 --- a/tests/test_router_mount.py +++ b/tests/test_router_mount.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, FastAPI +from fastapi import FastAPI, APIRouter from fastapi.testclient import TestClient @@ -22,4 +22,4 @@ def test_mount_on_router(): client = TestClient(app) assert client.get("/api/app").status_code == 200 - assert client.get("/api/subapi/sub").status_code == 200 + assert client.get("/api/subapi/sub").status_code == 200 \ No newline at end of file