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
| Parameter | Default and behavior |
|---|---|
params | Default: None. Optional[Dict[str, Any]]. Query parameters to set. Merged with existing params. Pass None to keep current params, {} to clear them. |
path | Default: None. Optional[str]. Optional new path. Defaults to current path. |
replace | Default: 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
| Parameter | Default and behavior |
|---|---|
path | Required. str. URL path to navigate to (e.g. "/items/42/"). |
params | Default: None. Optional[Dict[str, Any]]. Optional query parameters. |
replace | Default: 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
| Task | Use |
|---|---|
| Change a filter or page number in the current view | live_patch(params={...}) |
| Move to a different LiveView | live_redirect(path) |
| Replace the current history entry | Pass 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.