how to hide a page from sidebar

Hello Community,

I’m new to Streamlit and creating an application where i want to hide a page that are inside the pages directory. Like i do have page1.py, page2.py and page3.py now i don’t want to show the page2.py on the sidebar.

i used this code to hide:

show_pages(
    [
        Page("page1.py"),
        Page("page3.py"),
    ]
)
hide_pages(
    [
        "page2",
    ]
)

Using this code i’m able to hide the page2 but when i use the file page2.py in my code then i’m getting this error:

StreamlitAPIException: Could not find page: page2.py. Must be the file path relative to the main script, from the directory: app. Only the main app file and files in the pages/ directory are supported.

this is how i use the page2.py in my code:

if st.button("submit"):
    st.switch_page("pages2.py")