2017-02-20 298 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,开发服务器没有任何东西在那个地址为你服务,所以你需要告诉它回退到你的索引以允许它加载正确的路线。