Navigation

Patch vs Navigate

What each navigation mode actually does to the socket

  • Link
  • handle_params

Key concepts

patch and navigate both keep the browser on the same page without a full reload, but they do different things to the LiveView process underneath: patch calls handle_params/3 on the LiveView that's already running; navigate mounts a brand new one, in the same connection.

Current path
/examples/link-demo
Mount count
1
Params update count
1

How it works

mount_count is stored in the process dictionary, not in an assign, specifically so it survives a remount — every route in this app's router lives in the single default (unnamed) live session, so navigate reuses the same BEAM process even though it calls mount/3 again from scratch.

Click "patch": the URL changes, params_update_count goes up, mount_count does not — same process, same mount, only handle_params/3 ran again. Click "navigate": mount_count goes up too — a fresh LiveView, reusing the connection but not the state.