A few notes: 1. You want to derive from Route and not RouteBase if you want to just specify constraints. Constraints are introduced in the Route class. 2. There is nothing wrong with specifying the constraints like you have (explicitly in GetRouteData) it's just not extensible. 3. The path.Containts("api") is not a very good constraints and similarly not the one with "ui", it will fail for several reasons (case insensitivity and strings like "maping" will fail it).
So you want to consider something like:
var segments = path.Split(new[] { '/' });
segments.Any(segment => segment.Equals("api", StringComparison.OrdinalIgnoreCase) ||
segment.Equals("ui", StringComparison.OrdinalIgnoreCase));