The question is
If a logged in user visits the / route, make them redirect to the /guess route.
I have
scope "/", PentoWeb do
pipe_through :browser
get "/", PageController, :home
end
and
scope "/", PentoWeb do
pipe_through [:browser, :require_authenticated_user]
live_session :require_authenticated_user,
root_layout: {PentoWeb.Layouts, :root},
on_mount: [{PentoWeb.UserAuth, :ensure_authenticated}] do
live "/users/settings", UserSettingsLive, :edit
live "/users/settings/confirm_email/:token", UserSettingsLive, :confirm_email
live "/guess", WrongLive
end
end
Because the user must be logged in before redirect “/” to “/guess”, I delete the get "/", PageController, :home
line , and add a new line get "/", WrongLive
in live_session , to make route “/” inside the same live_session . But it shows
(CompileError) lib/pento_web/router.ex:75: undefined function get/2 (there is no such import)
(phoenix_live_view 0.19.3) expanding macro: Phoenix.LiveView.Router.live_session/3
lib/pento_web/router.ex:69: PentoWeb.Router (module)
(phoenix 1.7.6) expanding macro: Phoenix.Router.scope/3
lib/pento_web/router.ex:66: PentoWeb.Router (module)
What is the best way to do it?