Is it possible to create dynamic routes in runtime?

Noob question: I’m wondering how will I pull this off.

The scenario:

  • The base url is example.com
  • User created a post that has a slug (e.g. about-us)
  • This slug is added in router file
  • Route for that case will be example.com/about-us
  • Router.ex has definitions like:
scope "/", AppWeb do
  pipe_through :browser
  live "/collections", CollectionLive.Index, :index
  # ??? How do I create dynamic routes on this one?
end

Will a regular parametrized route not work for what you want? From the docs:

get "/pages/:page", PageController, :show

matches /pages/hello and dispatches to the show action with %{"page" => "hello"} in params .

https://hexdocs.pm/phoenix/Phoenix.Router.html#module-routing

1 Like

The question is: what is the use case? Why would you want ‘static’ routes made at runtime?

Depending on the use case, we might come up with a solution other than them one given above.