在我的反应应用程序中,我使用react-router
在页面之间导航。当我点击链接时,页面将首次显示。但是,当我以前刷新页面时,它显示Cannot /Get pageName
错误,我通过在historyApiFallBack: true
文件中添加webpack.config.js
来解决此问题。但是我没有在重新加载页面中看到数据。我的意思是来自服务或静态json对象的数据不会从redux
呈现到react
。例如:它显示页面,但选择框不包含选项(选项是
来自一些服务json对象)。
Routes.js
import React from 'react';
import {Route, IndexRoute} from 'react-router';
import App from './components/App';
import ViewPage from './components/ViewPage';
import HomePage from './components/HomePage';
import CreatePage from './components/CreatePage';
export default (
<Route path="/" component={App}>
<IndexRoute component={HomePage} />
<Route path="viewpage" component={ViewPage} />
<Route path="createpage" component={CreatePage} />
</Route>
);
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import {Router, browserHistory} from 'react-router';
import {Provider} from 'react-redux';
import configureStore from './store/configureStore';
import routes from './routes';
export const store = configureStore();
ReactDOM.render(<Provider store={store}>
<Router history={history} routes= {routes} />
</Provider>, document.getElementById('app'));
ConfigureStore.js
import { createStore, applyMiddleware } from 'redux';
import rootReducer from '../reducers/index';
import thunk from 'redux-thunk';
export default function configureStore(initialState){
return createStore(
rootReducer,
initialState,
applyMiddleware(thunk)
);
}
请建议......
谢谢, Shash