Page navigation did not show the page

dear boss
as per this link Additional Streamlit features - Streamlit Docs
I created three Python files for page navigation that function correctly. However, when I utilize the user input condition triggered by a button press, it fails to operate as expected. The page does not display when I press the button, and upon clicking on the page, it shows without the button. It does not display the page as intended. Please review my code and provide the correct solution and code.

thank you for your help

Can you share your code? I just copied the example for docs and ran it to confirm there wasn’t a typo. It ran as expected.

this ismy code
import streamlit as st

name = st.text_input(“Enter Your name”)

if st.button(‘Check availability’):

 # Define the pages
main_page = st.Page("main_page.py", title="Main Page", icon="🎈")
page_2 = st.Page("page_2.py", title="Page 2", icon="❄️")
page_3 = st.Page("page_3.py", title="Page 3", icon="🎉")

Set up navigation

if name=='a':
    pg = st.navigation([main_page, page_2, page_3])
elif name=='b':
    pg = st.navigation([main_page,  page_3])
# Run the selected page
pg.run()

Can you formaty your code in a single code block so the indentation is readable? I don’t understand what the button is supposed to be doing.

yes boss

import streamlit as st

name = st.text_input(“Enter Your name”)

if st.button(‘Check availability’):
main_page = st.Page(“main_page.py”, title=“Main Page”, icon=“:balloon:”)
page_2 = st.Page(“page_2.py”, title=“Page 2”, icon=“:snowflake:”)
page_3 = st.Page(“page_3.py”, title=“Page 3”, icon=“:tada:”)

if name=='a':
    pg = st.navigation([main_page, page_2, page_3])
elif name=='b':
    pg = st.navigation([main_page,  page_3])

pg.run()

You still didn’t format your code as a single code block. Please put ``` on a line before and after your code, so the whole thing is formatted like code, like this:

import streamlit as st

if foo:
    if bar:
...

Can you also describe exactly what you expect the code to do?

You’ll probably find this tutorial helpful for implementing dynamic navigation Create a dynamic navigation menu - Streamlit Docs

see code and error when clieck on page

import streamlit as st
if “mfapage” not in st.session_state:
st.session_state.mfapage = None

name = st.text_input(“Enter Your name”)

if st.button(‘Check availability’):
main_page = st.Page(“main_page.py”, title=“Main Page”, icon=“:balloon:”)
page_2 = st.Page(“page_2.py”, title=“Page 2”, icon=“:snowflake:”)
page_3 = st.Page(“page_3.py”, title=“Page 3”, icon=“:tada:”)

if name=='a':
    st.session_state.mfapage = st.navigation([main_page, page_2, page_3])
elif name=='b':
    st.session_state.mfapage = st.navigation([main_page,  page_3])

st.session_state.mfapage.run()