djust docs
Browse documentation
reference

Navigation methods

Navigation methods on the LiveView base class, generated.

On this page

Navigation methods on LiveView, generated from the framework manifest.

2 entries.

live_patch

self.live_patch(
    params: Optional[Dict[str, Any]] = None,
    path: Optional[str] = None,
    replace: bool = False,
) -> None
ParameterDefault and behavior
paramsDefault: None. Optional[Dict[str, Any]]. Query parameters to set. Merged with existing params. Pass None to keep current params, {} to clear them.
pathDefault: None. Optional[str]. Optional new path. Defaults to current path.
replaceDefault: False. bool. If True, use replaceState instead of pushState.

Update browser URL without remounting. Triggers handle_params().

live_redirect

self.live_redirect(
    path: str,
    params: Optional[Dict[str, Any]] = None,
    replace: bool = False,
) -> None
ParameterDefault and behavior
pathRequired. str. URL path to navigate to (e.g. "/items/42/").
paramsDefault: None. Optional[Dict[str, Any]]. Optional query parameters.
replaceDefault: False. bool. If True, use replaceState instead of pushState.

Navigate to a different LiveView over the existing WebSocket (no page reload).

Choose the right navigation method

TaskUse
Change a filter or page number in the current viewlive_patch(params={...})
Move to a different LiveViewlive_redirect(path)
Replace the current history entryPass replace=True

Keep a filter in the URL

from djust.decorators import event_handler

@event_handler()
def filter_results(self, category="all", **kwargs):
    self.category = category
    self.live_patch(params={"category": category, "page": 1})

def handle_params(self, params, uri):
    self.category = params.get("category", "all")

Implement handle_params() to restore state when the URL changes, including browser back and forward navigation. See Navigation for links, redirects, query parameters, and complete examples.