当我导航到http://localhost:8080
时,产品页面会按预期显示。但是,当导航到http://localhost:8080/basket
时,我会在浏览器中收到消息:
不能GET / basket
这是我的routes.js:
import React from 'react';
import { AppContainer } from 'react-hot-loader';
import { Router, Route, browserHistory, IndexRoute } from 'react-router';
import store from './store/store.js';
import { Provider } from 'react-redux';
import Error404 from './components/Error404.jsx';
import App from './containers/App.jsx';
import ProductsArea from './containers/shop/ProductsArea.jsx';
import BasketArea from './containers/shop/BasketArea.jsx';
const routes = () => (
<AppContainer>
<Provider store={store}>
<Router history={browserHistory}>
<Route path="/" component={App}>
<IndexRoute component={ProductsArea} />
<Route path="basket" component={BasketArea} />
</Route>
<Route path="*" component={Error404} />
</Router>
</Provider>
</AppContainer>
);
export default routes;
答案 0 :(得分:2)
我将historyApiFallback: true
添加到我的webpack.config.js文件中:
module.exports = {
...
devServer: {
historyApiFallback: true,
hot: true,
contentBase: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
...
}