View Source Navigation

The navigationPath is handled by the LiveSessionCoordinator. The LiveViewCoordinator receives navigation events from the Phoenix LiveView over the channel, and sends the navigation request to the session coordinator.

Kinds

There are two styles of navigation, based on how they impact the window.history on the browser.

push

This style appends a history entry.

In the case of SwiftUI, this means there is a system page push animation, and a back button is available to navigate to the previous page.

replace

This style replaces the current history entry.

In the case of SwiftUI, this means the top-most entry in the navigationPath is replaced with the new route. No back button is available to return to the previous page.

Events

There are three main navigation events in Phoenix LiveView.

When reconnecting on a new channel, the redirect key is used instead of the url key in the connect params.

redirect

This method sends a redirect event.

Can also be received in response to an event.

"redirect": {
    "to": "<path>"
}

This performs a push style navigation.

The channel is closed and a new channel connects on the same socket.

push_navigate

This method sends a live_redirect event.

Can also be received in response to an event.

"live_redirect": {
    "kind": "<push|replace>",
    "to": "<path>"
}

The channel is closed and a new channel connects on the same socket.

push_patch

This method sends a live_patch event.

{
    "kind": "<push|replace>",
    "to": "<path>"
}

The channel persists, unlike other forms of navigation. Only the query parameters of the URL are changed.