fix: enable mounting sub-applications under APIRouter by jonathan-fulton · Pull Request #14793 · fastapi/fastapi

@jonathan-fulton

Added support for mounting sub-applications on APIRouter with proper
prefix handling:

1. Override mount() in APIRouter to automatically apply the router's
   prefix to the mount path

2. Handle Mount routes in include_router() to apply the include prefix

This allows patterns like:
    router = APIRouter(prefix='/api')
    router.mount('/subapp', FastAPI())
    app.include_router(router)

Which correctly routes requests to /api/subapp/...

Note: Mounts must be added before include_router() is called, as
include_router copies routes at call time. This is consistent with
how other routes work.

Fixes fastapi#10180