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)

Parameters

page (str)

The file path (relative to the main script) of the page to switch to.

Example

Consider the following example given this file structure:

your-repository/
├── pages/
│   ├── page_1.py
│   └── page_2.py
└── your_app.py
import streamlit as st

if st.button("Home"):
    st.switch_page("your_app.py")
if st.button("Page 1"):
    st.switch_page("pages/page_1.py")
if st.button("Page 2"):
    st.switch_page("pages/page_2.py")
forum

Still have questions?

Our forums are full of helpful information and Streamlit experts.