我在redux store中使用历史记录有问题。
这是我的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)));
我遇到的错误是:
编译失败。
./src/redux/store.js模块未找到:无法解析"历史/createBrowserHistory"/home/salathiel/文件/realcamuniv/src/回家的">
我们尝试访问历史记录的方式已被弃用,这是警告
Warning: Please use require("history").createBrowserHistory instead of require("history/createBrowserHistory"). Support for the latter will be removed in the next major release
试试这个
import { createBrowserHistory } from 'history'
export const history = createBrowserHistory();