这是这一节我的代码截图,然后上面报错之后,我反复对比了很久不知道错哪了
在这里输入代码
[**index.js**]
import React from 'react';
import ReactDom from 'react-dom';
import { Provider } from 'react-redux';
import Container from './Main/Container.jsx';
import { store,history } from './store.js';
import { ConnectedRouter } from 'react-router-redux';
ReactDom.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<Container />
</ConnectedRouter>
</Provider>,
document.getElementById('root')
);
[**store.js**]
import { createStore,applyMiddleware } from 'redux';
import mainReducer from './reducers/main.js';
import thunk from 'redux-thunk';
import createHistory from 'history/createHashHistory'
import { routerMiddleware } from 'react-router-redux'
// 创建基于hash的history
const history = createHistory();
// 创建初始化tab
history.replace('home');
// 创建history的Middleware
const historyMiddl = routerMiddleware(history);
const store = createStore(mainReducer, applyMiddleware(thunk,historyMiddl));
if (module.hot) {
module.hot.accept('./reducers/main', ()=>{
const nextRootReducer = require('./reducers/main.js').default;
store.replaceReducer(nextRootReducer)
});
}
module.exports = {
store,
history
}
**[main.js]**
import tabReducer from './tabReducer.js';
import categoryReducer from './categoryReducer.js';
import contentListReducer from './contentListReducer.js';
import orderReducer from './orderReducer.js';
/* import scrollViewReducer from 'component/ScrollView/scrollViewReducer.js'; */
import { combineReducers } from 'redux';
import { routerReducer } from 'react-router-redux';
const reducers = combineReducers({
tabReducer,
categoryReducer,
contentListReducer,
orderReducer,
router: routerReducer
});
export default reducers;
[main.jsx]
import React from ‘react’;
import { connect } from ‘react-redux’;
import { Route, withRouter } from ‘react-router-dom’;
import BottomBar from ‘…/BottomBar/BottomBar.jsx’;
import Home from ‘…/Home/Home.jsx’;
import Order from ‘…/Order/Order.jsx’;
import My from ‘…/My/My.jsx’;
class Main extends React.Component{
constructor(props){
super(props);
}
render(){
return (
<div>
<Route path="/home" exact component={Home} />
<Route path="/order" component={Order} />
<Route path="/my" component={My} />
<BottomBar />
</div>
);
}
}
export default withRouter(connect(
/* state =>({
}) */
)(Main));
[BottomBar]
import ‘./BottomBar.scss’;
import React from ‘react’;
import { connect } from ‘react-redux’;
import { NavLink, withRouter } from ‘react-router-dom’;
/* import { changeTab } from ‘…/actions/tabAction.js’; */
/**
@constructor
@description 首页底部tab栏
*/
class BottomBar extends React.Component{
constructor(props){
super(props)
}
changeTab(item){
this.props.history.push(item.key);
}
renderItems(){
let tabs = this.props.tabs;
return tabs.map((item,index)=>{
let cls = item.key + ’ btn-item’;
let name = item.name;
return(
<div key={index} className={cls}>
<NavLink to={"/" + item.key} activeClassName="active" onClick={()=>this.changeTab(item)}>
<div className="tabs-icon"></div>
<div className="btn-name">{name}</div>
</NavLink>
</div>
)
})
}
render(){
return(
这个就是那节课改动的页面的代码