How to call async function when click browser back button

330 Views Asked by At

There is a list and a detail page. If I click the Back button on the browser on the Details page, the asynchronous function will act, which will change the state. What I want is that when this asynchronous function works successfully, it goes back to the list page, and on the list page, I want to get a list with an updated status. However, unlike what I thought, there are cases where the list is loaded first and the status is updated after that. How can we solve this problem? I use svelte.

  

  onMount(async () => {
    if (!accessToken) {
      navigate('/login')
      return
    }
    window.addEventListener('popstate', async (event) => {
      
      await resetData()

      history.pushState(null, '', config.HOME_PATHNAME)
    })
  })

Any advice or response is always welcome Thank you

0

There are 0 best solutions below