andrea

andrea

Can Phoenix LiveView be used in multi-page applications or does it have to be a SPA?

Can Phoenix LiveView be used in multi-page applications, unlike React/Vue/Blazor which seems to be targeted for SPA?

Most Liked

davearonson

davearonson

I don’t see any reason why not. After all, you can always set a link to go to a fresh page, whether that one has LiveView on it or not.

malloryerik

malloryerik

Yeah, LiveView webapps are kind of like anti-SPAs. You can find dozens of descriptions like this but here goes: Phoenix apps with LiveView pages are multi-page apps where some pages are regular http pages and some are LiveView pages, and the router, back buttons, urls and so on all work just like normal. If you want to only use LiveView pages in a Phoenix app that’s possible, though I think that typically at least login pages will be http.

The difference between traditional http pages and LiveView pages is that instead of an http connection which connects, sends html and data transfers and immediately disconnects, LiveView pages use a websocket connection which remains open, more like a telephone connection as an example, and push html and data changes on that page without reconnecting. (Normal Phoenix http pages are also great at establishing websocket connections, but aren’t designed to automatically send html changes over the wire.)

When you navigate from one LiveView page to another in the same app you’ll do it using the router and a new connection will be established, quite normal and delightfully boring. You can also have LiveView components inside of your LiveView pages, so basically LiveViews nested inside of other LiveViews, kind of SPA-ish but simpler.

Last, nothing stops you from using Vue, React, Svelte and so on inside of an app that has LiveViews, and even inside of LiveViews themselves (not saying it’s a necessarily a good idea). Here’s a library to help with using React components directly inside of LiveViews:

Where Next?

Popular Backend topics Top

IhorYachmenov
Hello. I have an iOS app where needs a proxying website through private server(HTTP / HTTPS proxy), but its idea each time has some trou...
New
Jsdr3398
Are there any databases that require no setup (can be shipped in a small zip together with the project)?
New
Fl4m3Ph03n1x
Background I am trying to get a Github Action working with Windows and Bakeware because I am trying to create a release using it. Howeve...
New
Fl4m3Ph03n1x
Background I have recently been delving into more functional code. My objective right now is to get something similar to the IO Monad (in...
New
GermaVinsmoke
Does anyone know beginner friendly Elixir/Phoenix Open source projects? For learning purpose :slightly_smiling_face:
New
sona11
If isReachable throws an IOException in Java, what is the right step to do and why? The application, I believe, should halt the process ...
New
sona11
I wrote this code to calculate Fibonacci numbers by specifying the size. The results are correct, however the one thing that concerns me ...
New
Sumityadav
Hello all, I am new to learning Java Programming and want to learn java from scratch. I was writing a Java program to get the first and l...
New
Fl4m3Ph03n1x
Background When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error: * assembling mark...
New
Fl4m3Ph03n1x
Background As I often do, I read books to learn and improve myself. I also enjoy teaching and helping others when I can, so this is somet...
New

Other popular topics Top

PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
PragmaticBookshelf
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1143 25816 759
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
AstonJ
Biggest jackpot ever apparently! :upside_down_face: I don’t (usually) gamble/play the lottery, but working on a program to predict the...
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New
gfqdjb
I just came across this tool. It looks interesting. Open WebUI is an extensible, feature-rich, and user-friendly self-hosted AI platfor...
New