I have a sidebar as a function component that takes the current route as well as a list of items to display:
[%{
title: "some title",
route: ~p"/some/route"
}, ...]
The sidebar displays all of the items vertically, and if any of their routes matches the current route, then it adds a little highlight to display the currently selected page.
But now I would like to embed this into my layout, so that all dead and LiveViews can use this. So I put this in my app layout, since I would like the highlighted item to update if i live_redirect
. But here is where I run into my issue.
If my app is rendering a dead view, I can access the @conn
variable here, and obtain the current route to pass to my sidebar component. But if it is rendering a LiveView @conn
is not available, and I must use @socket
, where the current route is not available. Is there a way I can obtain the current route from the socket, or is there any other solution for obtaining the current route form the layout regardless if the page being rendered is a dead view/LiveView, and also one that updates across live_redirects
etc.