是否可以在不删除组件状态React Router的情况下删除当前页面的查询参数?

I want to remove query param ?error=true from my current screen before that I need to store that information in state. but if I use props.history.replace, The state information of my current component will loss. Is there any way to remove query param without re-rendering with react router

评论
  • xiste
    xiste 回复

    我没有使用React进行检查,但是已经使用Angular进行了尝试,

    You can create the current url like this and remove the query params that you want. If you have many query params than param error, you may need to get them and dynamically remove error param and add it to the end of the below variable

    const updatedUrl = window.location.protocol + "//" + window.location.host + window.location.pathname
    

    现在您可以使用

    window.history.pushState({path:newurl},'',newurl);