简体   繁体   中英

how to reload the page after call handleDelete but it stays on the current page,not reload to the homepage, i want stay on the current page

handleDelete: props => (id) => {
  props.deleteClaim(id)
  .then(() => {
    message.success('success delete')
  })
  setTimeout(() => {
    window.location.reload(true)
  }, 1000)
},

the problem is that every time I run the delete function on page 2, I immediately return to the main page,

how to do it so that when reloading it can stay on page 2.

Remove setTimeOut code cuz it makes you move to the main Page. "Re-load" means Browser re-load your whole page again which means Browser refresh your App and show you the main page again.

handleDelete: props => (id) => {
  props.deleteClaim(id)
  .then(() => {
    message.success('success delete')
  })
},

I don't think reloading the page in React is a good idea as it fails the purpose of SPA (Single Page Application). If you want to keep yourself on the page 2 then why reloading in the first place? Upon delete, you might be thinking that the deleted object should be reflected on the front-end, so for that there can be two scenarios you can do:

  • Either refetch your data
  • Or delete that the object from your front-end list upon success of your API response

In order to stay on the same page after refresh, the page must be on a separate route. In this case, after refreshing the page, you will remain on it. My advice to you is to use a state manager, do not complicate your life. If you want your data to be saved when the page is refreshed, you need to store it in localstorage or get it from the server. There are no other ways

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM