相关疑难解决方法(0)

使用window.history.pushState函数时,无法在"历史记录"错误上执行"pushState"

我正在使用window.historyJavascriptMVC应用程序为每个控制器启用后退/前进/刷新功能.每次我加载一个新的控制器,我都 window.history.pushState用来为历史添加一个新的状态.然后在返回/刷新时我正在使用已保存的状态并重新使用数据来再次构建控制器.

除了特定场景中的一个问题外,整个想法都很好.我收到以下错误:

无法在"历史记录"上执行"pushState":无法克隆对象.

在其他方案中添加相同的数据没有问题.什么可能导致此错误?谢谢你的帮助.

javascript html5 javascriptmvc

22
推荐指数
2
解决办法
2万
查看次数

未捕获的 DOMException:无法在“历史”上执行“pushState”:函数 () { [本机代码] } 无法克隆

我正在 Visual Studio 2017 提供的 reactjs 模板中创建一个小型 Web 应用程序。我陷入了一种情况,我希望将函数作为状态传递给子组件,然后通过子组件调用该函数。我有一个标题组件,其中有一个名为setLogInTrue()的方法,我想将其传递给我的 SignIn 组件。以下是我的代码:-

头文件.tsx

class HeaderState {
isLoggedIn: boolean;
}

export class Header extends React.Component<HeaderProps, HeaderState> {
constructor() {
    super()
    this.state = ({ isLoggedIn: false });
    this.setLogInTrue= this.setLogInTrue.bind(this);
}

setLogInTrue() {
    this.setState({ isLoggedIn: true });
}

public render(){
//Some elements
<NavLink className="link header_row_link" to={{ pathname: '/signIn', state: this.setLogInTrue }}> //<-- i thought this would work and give the function in the location of SignIn components state but it does not. …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs visual-studio-2017

5
推荐指数
2
解决办法
9356
查看次数