反应路由器页面无法刷新

时间:2019-01-12 10:08:43

标签: javascript reactjs react-router-v4 react-router-dom

我想尝试嵌套路由,但是它不起作用

Codesandbox Link

场景: 当我第一次在 / category / bags 上路由时,它可以正确呈现 但是当我在此页面上刷新时,它会显示错误页面未找到

我尝试使用 this.props.match.url和this.props.match.path ,但是在这里我遇到了错误,就像没有prop match.url < / p>

我尝试了以下链接

https://reacttraining.com/react-router/web/guides/quick-start

How to include the Match object into a ReactJs component class?

Nested routes with react router v4

2 个答案:

答案 0 :(得分:1)

我看过您的代码,发现您在父级路由中使用了完全相同的代码:

<Route exact path="/category" component={Category} />

如果您从父级路由中删除了确切地址,那么它将正常工作:

<Route path="/category" component={Category} />

答案 1 :(得分:0)

尝试使用ConnectedRouter from ‘react-router-redux’代替BrowserRouter from 'react-router-dom'

我希望这篇文章能对您有所帮助:

https://medium.com/@Dragonza/react-router-problem-with-gh-pages-c93a5e243819

相关问题