How to refer page in multipages?

Summary

The multipage tutorial is useful. However, it doesn’t mention how to refer pages.

Steps to reproduce

Let’s say we want to cite page2 using markdown in main_parge.

How to make [page2](??label??) jumping to page2?

Code snippet:

# Contents of ~/my_app/main_page.py
import streamlit as st
st.title("Main page")
st.markdown("[page2](??label??)")

# Contents of ~/my_app/pages/page_2.py
import streamlit as st
st.title("Page2")
1 Like

thank you for this. It was a lot of help!! I wonder how can we jump to the page but stay in the same window or how to close the window we just left? I’m very new to Streamlit, sorry if it is a very beginner question. :handshake:

You can use this once you know the link of your website:

st.markdown('<a href="http://localhost:8501/page2" target="_self">page2</a>', unsafe_allow_html=True)
2 Likes

thank you!

The method described above by zxdawn will work, but it will reset the session state.
If you want to maintain the session state when you switch between pages of a multi-page app, then you’ll need the switch_page function:
https://extras.streamlit.app/Switch%20page%20function

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.