2016-06-17 3 views
9

リアクタがルータ名のon the react-router docsとして使用しようとしています。これは、base hrefが廃止されたためです。ここで ベース名が正しく動作しません

は、私が今持っているものです。
import { Route, Router, useRouterHistory } from 'react-router'; 
 
import { createHistory } from 'history'; 
 
import { render } from 'react-dom'; 
 

 
var history = useRouterHistory(createHistory)({ 
 
    basename: '/subdirectory' 
 
}); 
 

 
render(
 
    <Router history={history}> 
 
    <Route path='/' component={App}> 
 
     <Route path='next' component={Next} /> 
 
    </Route> 
 
    </Router>, 
 
    document.getElementById('root') 
 
);

Appコンポーネントをレンダリング)予想通り、私はhttp://the-url.com/subdirectoryページが読み込まに行くとき。しかし、http://the-url.com/subdirectory/nextに行くと404エラーが出ます。私のnginxの設定ファイルは次のとおりです。

location /subdirectory { 
    alias /path/to/index.html; 
    index index.html; 
    try_files $uri $uri/ /path/to/index.html; 
} 
+3

これにはどのような解決策がありますか? – Jatin

+1

誰にもこの解決策が見つかりましたか? –

+1

これの解決方法はまだありますか? – stefanil

答えて

2

私が使用して、それを解決:

import { Router, useRouterHistory } from 'react-router' 
import createBrowserHistory from 'history/lib/createBrowserHistory' 

const history = useRouterHistory(createBrowserHistory)({ 
    basename: '/', 
}) 

<Router history={history}> 

私は問題がhistoryパッケージの異なるバージョンだったと思います。 [email protected][email protected]を使用し、historyはすでに4.5.1になっています。 したがって、正しいバージョンのhistoryパッケージをインストールしてください。

+0

開発には問題ありませんが、 –

関連する問題