简体   繁体   English

React Router/History 无法解析“history/createBrowserHistory”

[英]React Router/History Can't Resolve "history/createBrowserHistory"

I cloned my react project today and the project was working fine on my other mac.我今天克隆了我的 React 项目,该项目在我的另一台 Mac 上运行良好。 Then I started to face some problems with my router, especially the history.然后我的路由器开始出现一些问题,尤其是历史记录。 The code in my history.ts is:我的history.ts中的代码是:

import createHistory from 'history/createBrowserHistory';

export default createHistory();

My app.tsx is:我的app.tsx是:

import React from 'react';
import { Route, Router, Switch, } from 'react-router-dom';
import { connect } from 'react-redux';

import history from '../history';

const App = (props: any) => {
    return (
        <div>
            <Router history={history}>
                <div>
                    <Header/>
                    <Route path="/" exact component={Home}/>
                    <Route path="/about" exact component={About} />
                    <Route path="/media" exact component={Media}/>
                    <Switch>
                        <Route path="/login" exact component={Login}/>
                        <PrivateRoute path="/menu" exact component={Menu} auth={props.isSignedIn} />
                        <PrivateRoute path="/create" exact component={PostCreate} auth={props.isSignedIn} />
                        <PrivateRoute path="/delete/:id" exact component={PostDelete} auth={props.isSignedIn}/>
                    </Switch>
                </div>
            </Router>
        </div>
    );
};

I tried to change my history.ts to:我试图将我的history.ts更改为:

import { createBrowserHistory } from "history";
export default createBrowserHistory();

and no success, I also tried to change to没有成功,我也尝试更改为

import { createBrowserHistory, History } from "history";
const history: History = createBrowserHistory();
export default history

And no success too, it's strange because my application was working fine months ago.也没有成功,这很奇怪,因为我的应用程序几个月前运行良好。 I've searched all over Stack Overflow and no solution seems to fit.我搜索了整个 Stack Overflow,似乎没有合适的解决方案。 Any help will be appreciated.任何帮助将不胜感激。

I've solved, I noticed that the createBrowserHistory.d.ts weren't getting created.我已经解决了,我注意到没有创建createBrowserHistory.d.ts Probably because of my fault yarn install .可能是因为我的错误yarn install I removed the project and re-cloned and installed the libraries using npm Then worked.我删除了项目并使用npm重新克隆并安装了库然后工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM