开发者问题收集

无法解析“history/createBrowserHistory”

2021-02-25
2229

我在 redux store 中使用历史记录时遇到问题。

here is my store.js

 import { applyMiddleware, createStore } from 'redux';
// import { createLogger } from 'redux-logger'
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';
import reducer from './reducer'; //Import our reducer
import thunk from 'redux-thunk'
import createHistory from 'history/createBrowserHistory';
export const history = createHistory();
// Build the middleware for intercepting and dispatching navigation actions
const myRouterMiddleware = routerMiddleware(history);
//Create our Store using createStore and the reducer as an argument.
export const store = createStore(
  reducer, composeWithDevTools(applyMiddleware(thunk)));

我遇到的错误是:

Failed to compile.

./src/redux/store.js Module not found: Can't resolve 'history/createBrowserHistory' in '/home/salathiel/Documents/realcamuniv/src/redux'

1个回答

您尝试访问历史记录的方式已被弃用,这是警告

警告:请使用 require("history").createBrowserHistory 而不是 require("history/createBrowserHistory")。对后者的支持将在下一个主要版本中被删除

请尝试这种方式

import { createBrowserHistory } from 'history'
export const history = createBrowserHistory(); 
Rmcr714
2021-02-25