【问题标题】:Browser history issues in reactjsreactjs中的浏览器历史问题
【发布时间】:2018-05-02 04:49:46
【问题描述】:

我正在尝试根据 reactjs 中的会话超时运行一个项目。但不幸的是发生了错误。这是错误,
'react-router' does not contain an export named 'browserHistory'.

【问题讨论】:

标签: reactjs


【解决方案1】:

我认为您正在使用 React Router 4。它围绕其中一些模块移动。您要么需要迁移代码以使用 v4,要么在 package.json 中降级 React Router。

React 路由器在这里提供了迁移指南:

https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/guides/migrating.md

【讨论】:

    【解决方案2】:

    我认为您正在使用 react-router 最新版本。在内部管理的新版本历史中。您可以使用 like 并且历史记录在您的组件道具中可用,例如 props.history

    import React from 'react';
    import { Route } from 'react-router';
    import { HashRouter, Switch } from 'react-router-dom';
    
    
    let RootApp = () => {   
       return (
          <div>
            <HashRouter>
                <Switch>                  
                  <PrivateRoute path='/admin' component={AdminRoute} /> 
                  <Route path='/login' component={LoginComponet}></Route>
                  <Route path='/**' component={LoginComponet}></Route>             
                </Switch>
            </HashRouter>
          </div>
        );
    }
    

    【讨论】:

      猜你喜欢
      • 2017-03-17
      • 1970-01-01
      • 1970-01-01
      • 2013-11-10
      • 2013-05-21
      • 2012-11-14
      • 2015-10-10
      • 2015-04-03
      • 1970-01-01
      相关资源
      最近更新 更多