react-router - 无法获取网址

时间:2017-03-15 22:24:07

标签: reactjs react-router

当我导航到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;

1 个答案:

答案 0 :(得分:2)

我将historyApiFallback: true添加到我的webpack.config.js文件中:

module.exports = {
    ...
    devServer: {
        historyApiFallback: true,
        hot: true,
        contentBase: path.resolve(__dirname, 'dist'),
        publicPath: '/'
    },
    ...
}