Multipage support with Streamit Routes (http://DOMAIN?nav=/settings/profile)

As an addition to the Extra-Streamlit-Components github with thousands of downloads on pip, url based routing is now possible. This leverages query parameters to manage your app’s pages using static routes such as http://DOMAIN?nav=/settings/profile. Dynamic routing to be supported in near future. Get it by upgrading the pip package with: pip install --upgrade extra-streamlit-components
Demo (this supports 2 routes ‘/home’ & ‘/landing’):

 @st.cache(allow_output_mutation=True, hash_funcs={"_thread.RLock": lambda _: None})
  def init_router():
      return stx.Router({"/home": home, "/landing": landing})

  def home():
      return st.write("This is a home page")

  def landing():
      return st.write("This is the landing page")

  router = init_router()
  router.show_route_view()

  c1, c2, c3 = st.columns(3)

  with c1:
      st.header("Current route")
      current_route = router.get_url_route()
      st.write(f"{current_route}")
  with c2:
      st.header("Set route")
      new_route = st.text_input("route")
      if st.button("Route now!"):
          router.route(new_route)
  with c3:
      st.header("Session state")
      st.write(st.session_state)

5 Likes