如何在反应路由器中更新 history.replace 上的路由器状态?

问题描述:

我的反应路由器具有状态 isActive(boolean) 值.当我使用 Link 组件重定向到不同的路由时,我可以按如下方式更新状态并且它工作正常:-

My react router has state isActive(boolean) value. When I use the Link component to redirect to different route I can update the state as follows and its working fine:-

<Link to={{
        pathname: "my-home-page",
        search: '?query=abc',
        state: { isActive: true }
}}>Go to Home</Link>

此外,当我使用 history.push 状态时,使用以下代码正确更新:-

Also when I use history.push state is updating correctly bu using below code:-

history.push({
               pathname: '/template',
               search: '?query=abc', 
               state: {
                isActive: true
               }
});

但是,当我在 javascript 中使用 history.replace 时,我无法更新状态.我正在尝试下面的代码,但它不起作用.

However when I am using history.replace in javascript I am not able to update the state. I am trying the below code however its not working.

history.replace({ pathname: 'home', search: '?query=abc', isActive: true});

有人知道我做错了什么吗?为什么在使用 history.replace

Anyone knows what I am doing wrong? Why my state is not updating while redirecting with history.replace

路由器是什么版本?在 History API 中,当我使用它时,第一个参数是路径名(没有对象,只有字符串),第二个参数是状态.

What version of the router is it? In History API, and when I've used it, the first parameter is the pathname (without object, just the string), and the second parameter is the state.