我正在玩弄react
并redux
尝试将一个基本的应用程序与react-routes
. 目前,我已经设法将以下适用于页面的内容放在一起Wrapper
,Home
但是如果我转到 localhost:8080/apps,“应用程序”页面似乎不会加载。我每次都收到404。
有什么想法我可能在这里出错了吗?
控制台中没有错误或警告,我尝试在网上查看几个示例,但似乎没有一个与我所拥有的特别不同,
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux'
import { browserHistory } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import Routes from './routes/routes';
import { configureStore } from './store/configureStore';
const rootElem = document.getElementById('mount');
const store = configureStore(browserHistory);
const history = syncHistoryWithStore(browserHistory, store);
const provider = <Provider store={store}><Routes history={history} /></Provider>;
ReactDOM.render(provider, rootElem);
路线/路线.js
import React from 'react';
import { Router, Route, IndexRoute } from 'react-router'
import { Wrapper, Home, Apps } from './../views';
class Routes extends React.Component {
render () {
const { history } = this.props;
return(
<Router history={history}>
<Route path='/' component={Wrapper}>
<IndexRoute component={Home}/>
<Route path='apps' component={Apps}/>
</Route>
</Router>
);
}
}
Routes.propTypes = {
history: React.PropTypes.object.isRequired
};
export default Routes;
存储/configureStore.js
import { createStore, applyMiddleware, compose } from 'redux';
import { routerMiddleware } from 'react-router-redux'
import createLogger from "redux-logger";
import thunk from 'redux-thunk';
import rootReducer from './../reducers'
export function configureStore(history, initialState = {}) {
const logger = createLogger();
const middleware = routerMiddleware(history);
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(thunk, middleware, logger),
window.devToolsExtension ? window.devToolsExtension() : f => f
)
);
return store;
}
减速器/index.js
import { combineReducers } from 'redux';
import { routerReducer } from 'react-router-redux';
export default combineReducers({
//...reducers,
routing: routerReducer
});