How to keep assigns on live redirect?

I’m new to Phoenix LiveView and after reading a few threads here, I still find it hard to understand whether it’s possible to keep socket assigns when changing pages.

Let’s take as an example the awesome LiveBeats project. When you navigate around the website, the sidebar assigns will get refetched even though it uses assign_new. Because the moment you do a live redirect the nav on mount gets called and the socket assigns is empty.

Anyway to keep the assigns when changing pages?

It is not possible to do this with live_redirect. Refetching the side bar assigns would be just the same as if it were a regular static site too.

If you want something closer to the “single page app” architecture you can use a single live view page, with a main component on each page in addition to a nav component. Then you live_patch between routes and change out the component.

There‘s also sticky liveviews for maintaining parts of a page across navigation.

4 Likes

TIL! Yes that would also work, neat!

3 Likes

Ohh nice! I must try it :slight_smile:
Thank you!