2017-02-20 167 views
0

我使用的反應 - 路由器,我有以下途徑反應路由器,路線不工作

<Route path = '/' component = {App}> 
    <Route path = '/login' component = {LoginContainer}> 
    </Route> 
</Route> 
從應用

現在,當我去「http://localhost」,那麼它工作正常,但是當我瀏覽到http://localhost/login然後我得到一個錯誤,說無法找到登錄。

+0

您使用的是哪種歷史? https://github.com/ReactTraining/react-router/blob/master/docs/guides/Histories.md –

+0

[React-router url無法在手動刷新或寫入時工作](http:// stackoverflow.com/questions/27928372/react-router-urls-dont-work-when-refreshing-or-writting-manually) –

回答

1

如果您使用的是webpack dev服務器,如果您想使用瀏覽器歷史記錄,則需要使用History API Fallback選項。

基本上,當你去http://localhost/login,開發服務器沒有任何東西在那個地址爲你服務,所以你需要告訴它回退到你的索引以允許它加載正確的路線。