Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何禁用React路由器中的后退按钮?_Reactjs_React Router - Fatal编程技术网

Reactjs 如何禁用React路由器中的后退按钮?

Reactjs 如何禁用React路由器中的后退按钮?,reactjs,react-router,Reactjs,React Router,我已尝试禁用浏览器中的“后退”按钮,但它只是将页面重新加载到路径=“/” 我怎样才能禁用浏览器的后退按钮,这样当用户点击它时什么也不会发生 export default class Main extends Component { componentDidMount() { const history = createBrowserHistory(); history.listen((newLocation, action) => { if (action

我已尝试禁用浏览器中的“后退”按钮,但它只是将页面重新加载到路径=“/”

我怎样才能禁用浏览器的后退按钮,这样当用户点击它时什么也不会发生

export default class Main extends Component {
  componentDidMount() {
    const history = createBrowserHistory();
    history.listen((newLocation, action) => {
      if (action === "POP") {
        history.go(0);
      }
    });
  }
  render() {
    return (
      <div>
        <Router>
          <Switch>
            <Route exact path="/" component={Home} />
            <Route path="/main/component1" component={Component1} />
            <Route path="/main/component2" component={Component2} />
            <Route path="/main/component3" component={Component3} />
          </Switch>
        </Router>
      </div>
    );
  }
}
导出默认类主扩展组件{
componentDidMount(){
const history=createBrowserHistory();
历史记录。收听((新位置、动作)=>{
如果(操作==“弹出”){
历史。go(0);
}
});
}
render(){
返回(
);
}
}

您不能真正阻止浏览器的“后退”按钮,但可以阻止过渡。