2016-06-22 15 views
5

Webpackとreact-rounterでプロジェクトをビルドします。 これは私のコードです:React-router bundle.jsでWebpackを使用していません

ReactDOM.render(
 
    <Provider store={store}> 
 
     <Router history={ browserHistory }> 
 
      <Route path='/' component={ App } > 
 
       <IndexRoute component={ Home } /> 
 
       <Route path="purchase" component={ Purchase } /> 
 
       <Route path="purchase/:id" component={ Purchase } /> 
 
      </Route> 
 
     </Router> 
 
    </Provider>, 
 
    document.getElementById('example') 
 
);

私は"http://127.0.0.1:3001/purchase"を要求すると、それが動作しています!アドレス"http://127.0.0.1:3001/purchase/a"にはエラーがあります。エラーメッセージを見る:enter image description here

マイWebpackDevServerの設定は次のとおりです。

new WebpackDevServer (webpack(config), { 
 
    publicPath: config.output.publicPath, 
 
    hot: true, 
 
    noInfo: false, 
 
    historyApiFallback: true 
 
}).listen(3001, '127.0.0.1', function (err, result) { 
 
     if (err) { 
 
      console.log(err); 
 
     } 
 
     console.log('Listening at localhost:3001'); 
 
    });

私は問題は、私を助けているかわかりません!

答えて

19

index.htmlにあるbundle.jsのパスを表す相対パスを使用しています。

あなたは

絶対パスはルートディレクトリとファイルやフォルダが含まれている他のすべてのサブディレクトリが含まれているあなたのindex.htmlにbundle.jsの絶対パスを使用する必要があります。

index.htmlと同じパスにある場合。

例えば、

public/index.html

public/bundle.js

これはあなたの問題を解決するだろう。

<script src="/bundle.js"></script> 
+0

驚くばかり!それは私の問題を解決する。君たちありがとう! –

+1

非常に素晴らしい!数時間前に答えが見つかったらいいと思う:p – challenger

+1

しかし、私のindex.htmlにはbundle.jsがありません。どうにかして相対パスで自動的に挿入されます。 – Curtis

関連する問題