Import routes from a library into my main Router

Hi all,

I have a phoenix 1.7 project that uses a local library we are developing.
I would like to import in my project’s router some routes defined in the library.

Is that even possible?

Thank you

There is Phoenix.Router.forward/4 or you can just glue together router pieces with macros:

defmodule MyApp.Web.Router do
  use MyExt.Web.Routes

defmodule MyExt.Web.Routes do

  defmacro __using__(_) do
    quote do
      scope "/myext", MyExt.Web do

Just be cautious that using forward won’t work with LiveView. LiveView needs to be able to find routes at compile time to gather metadata and therefore needs to be able to infer the router at compile time.


This looks like a good option: