diff --git a/modules/context/api.go b/modules/context/api.go
index 41d559f5b1..7d281b998a 100644
--- a/modules/context/api.go
+++ b/modules/context/api.go
@@ -362,6 +362,7 @@ func RepoRefForAPI(next http.Handler) http.Handler {
 				return
 			}
 			ctx.Repo.Commit = commit
+			ctx.Repo.TreePath = ctx.Params("*")
 			return
 		}