Define root path per router instead on endpoint level only

I am building application where I have separate routers for each part of the API (REST, UI, and GraphQL):

defmodule MyApp.Router do
  use Phoenix.Router

  forward("/graphql", MyApp.GraphQL.Router)
  forward("/api", MyApp.REST.Router)
  forward("/", MyApp.UI.Router)
end

Currently there is no problem with that as I can specify “sub-path” in API documentation (OpenAPI), but I see potential problem in future where the amount of routers can grow. Namely imagine situation where I would need to add new router, ex. MyApp.Foo.Router within scope /foo but within that controller I would need it to generate paths with that prefix, so I will need to workaround that by either remember to provide handcrafted %URL{} as the first parameter to the helper functions or to write it as /foo/<%= helper_path(…) %> (that second option will not work for other helpers though). What I would love to see is option :path similar to the Phoenix.Endpoint one passed either to Phoenix.Router.__using__/1 or (even better) to generated Router.init/1. That second option is even better as it allows me to define used route in the same place I define forwarding.

What are your opinions on such feature? Or maybe I missed something that is already possible.

I don’t know how to get rid of the routing issue for your solution. For this specific problem I think having separate endpoints with a master proxy is an acceptable solution. One can define an endpoint that proxies the others based on whatever logic you want. Domain. Route. Whatever. See this example.