Route Helpers - Verified route `~p`
We need to determine if we will be providing some sort of route helper in Beacon, and if so what it would look like.
How do you see this router helper working? Would it be some kind of sugar for defining routes in the router file? 🤔
Also, At the moment Beacon doesn't allow developers to dynamically router their sites because we are using live_session which require routes to be defined at compile time.
What if we advice this pattern here for dynamic routes instead:
scope "/sites/", BeaconWeb do
pipe_through :browser
pipe_through :beacon
# We can potentially introduce SessionLive if we need to enforce something on mount and do instead:
# live_session :beacon, on_mount: BeaconWeb.SessionLive
live_session :beacon do
live "/:beacon_site/*path", PageLive, :path
end
end
This only requires Beacon to pattern match against it on PageLive
def mount(%{"path" => path, "beacon_site" => site} = params, _session, socket) do
...
end
We might as well use https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#on_mount/1 to enforce some stuff if needed on LV mount - such as full redirects among different sites.
Wdyt @TheFirstAvenger?
The helpers would be similar to the Phoenix ones such as Routes.dashboard_path(@conn, :index). Interestingly enough, I just saw this feature in Phoenix 1.7, we might be able to implement something similar to this.
Requires more research, according to @leandrocp