Skip to content

Navigate

To navigate to another page, you can use me.navigate. This is particularly useful for navigating across a multi-page app.

Example

import mesop as me


def navigate(event: me.ClickEvent):
  me.navigate("/examples/navigate/about")


@me.page(path="/examples/navigate/home")
def home():
  me.text("This is the home page")
  me.button("navigate to about page", on_click=navigate)


@me.page(path="/examples/navigate/about")
def about():
  me.text("This is the about page")

API

navigate

Navigates to the given URL.

The URL can be an absolute URL (e.g., "http://example.com/page") or a root-relative URL (e.g., "/page").

Document-relative URLs (e.g., "page" or "./page") are not supported.

Query parameters should be passed using the query_params argument. If passed in the URL directly, they will be removed and a warning will be issued.

PARAMETER DESCRIPTION
url

The URL to navigate to.

TYPE: str

query_params

A dictionary of query parameters to include in the URL, or me.query_params. If not provided and open_in_new_tab is False, all current query parameters will be removed. When open_in_new_tab is True, the current page's query parameters are preserved unless explicitly overridden.

TYPE: dict[str, str | Sequence[str]] | QueryParams | None DEFAULT: None

open_in_new_tab

Whether to open the URL in a new browser tab. Defaults to False.

TYPE: bool DEFAULT: False