Programmatically switch the current page in a multipage app.
When st.switch_page is called, the current page execution stops and the specified page runs as if the user clicked on it in the sidebar navigation. The specified page must be recognized by Streamlit's multipage architecture (your main Python file or a Python file in a pages/ folder). Arbitrary Python scripts cannot be passed to st.switch_page.
| Function signature[source] | |
|---|---|
st.switch_page(page, *, query_params=None) | |
| Parameters | |
page (str, Path, or st.Page) | The file path (relative to the main script) or an st.Page indicating the page to switch to. |
query_params (dict, list of tuples, or None) | Query parameters to apply when navigating to the target page. This can be a dictionary or an iterable of key-value tuples. Values can be strings or iterables of strings (for repeated keys). When this is None (default), all non-embed query parameters are cleared during navigation. |
Examples
Example 1: Basic usage
The following example shows how to switch to a different page in a multipage app that uses the pages/ directory:
Example 2: Passing query parameters
The following example shows how to pass query parameters when switching to a different page. This example uses st.navigation to create a multipage app.
Still have questions?
Our forums are full of helpful information and Streamlit experts.
