Use st.navigation to turn several Streamlit pages into a selectable app flow. Give it a list of st.Page objects; it displays the navigation options and returns the page the user selected. section 8.4.1
The basic workflow is:
- Define pages with st.Page, including each page's file, title, and optional icon. section 8.4.1
- Pass the available pages to st.navigation as a list. section 8.4.1
- Call .run() on the returned Page so Streamlit loads the selected page. section 8.4.1
Show different pages after login
Store login state in st.session_state, then choose the navigation list conditionally: logged-in users receive Home and Log out, while other users receive Log in and Sign up. After login, set the user state and call st.rerun(); the logout page clears the state and reruns the app. section 8.4.3
Listing 8.8 main.py, revised yet again
import streamlit as st
from backend.hub import Hub
pages = {
"login": st.Page("frontend/login.py", title="Log in",
icon=":material/login:"),
"signup": st.Page("frontend/signup.py", title="Sign up",
icon=":material/person_add:"),
}
if 'hub' not in st.session_state:
st.session_state.hub = Hub()
page = st.navigation([pages['login'], pages['signup']])
page.run()
A complete minimal main.py example shows page definitions, shared session state, navigation creation, and page execution together. section 8.4.1
