Session state is not preserved when navigating pages


I am new to streamlit and I want to know if it is possible to preserve session state variable when navigating through pages. I am writing the pages as separate .py files in pages folder. I noticed that when I input text in a page then go to another page the text state is preserved only for 1 click after.

Steps to reproduce

Code snippet:

import streamlit as st

st.text_input('file path', key=tmp_filepath)
if len(st.session_state.tmp_filepath)

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

I want to input text in one page. Be able to use it in different pages and for it to be not be updated or erased unless I re-input the text.

Actual behavior:

Text input is only preserved after 1 page navigation