Implementing a menu compoenent

I’ve done some experiments with live_view (v0.19.x) regarding navigation between live_views without page reloading. I’ve placed a live component in the layout app.html.heex, as it will be used by all live_views by default, as the live component seems to run in the process as current the live_view, I started to implement a menu in the live component, to switch between different live_views. The current live_view update the state of the current selected menu item by using send_update. It all seems to work well, no page reloading, seamless switching and menu is updated accordingly, so I’m wondering if this is the right way to tackle such problems (placing a component in app.html.heex).?

BTW I used a live component because of the toggle state of the menu, in the case of smaller screen sizes.

If there are better solutions, please feel free to let us, the forum, know :slight_smile:

It’s generally advised not to store UI-only concerns like menu state on the server and to use JS commands instead. If you do this you won’t need a live component and thus won’t need send_update.

6 Likes