Redirecting to default Homepage when user reloads on any other page

Hi. I have a multi-page app with 2 pages. I am using st.navigation for navigating between pages.

so I have 3 scripts app.py, and then inside pages folder I have app_home.py, and app_task_history.py

In app.py, I have authentication logic, and if that is successful I load the pages like this -

    home_page = st.Page(
        page = "pages/app_home.py",
        title = 'Home',
        default= True,
    )

    task_history_page = st.Page(
        page = "pages/app_task_history.py",
        title = 'Task History',
    )

    pg = st.navigation(pages=[home_page, task_history_page])

    pg.run()

The default page is Homepage. Now the problem is, when the user is on the Task History page and reloads the page (not rerun), they are redirected to the Homepage.

What I want is users to stay on the Task History Page. I tried using the combination of session_state[ā€˜current_pageā€™] and st.switch_page() function, but that did not work for me.

So, is it any way to use session_state or something else to make this work?

Thanks.

If Iā€™m understanding what youā€™re saying:

When a page reloads, Streamlit starts a new session. Streamlit uses a websocket connection, so opening a new tab, refreshing the page, or losing connectivity for too long just starts a new session, unrelated to the previous one. If you are checking for authentication status in Session State on your pages and a page reloads, it would appear that you have a new user who isnā€™t logged in.

1 Like

Got it. I think this is the problem with streamlit-authenticator. I removed authentication and refreshing didnā€™t redirect me to the homepage.

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