React router 4 不会更新链接上的视图,但会在刷新时更新

2024-02-03

我正在使用以下简单的导航代码

<Router>
  <Switch>
    <Route exact path='/dashboard' component={Dashboard} />
    <Route path='/dashboard/accounts' component={AccountPage} />
  </Switch>
</Router>

<NavLink exact to={'/dashboard'}
         disabled={this.props.item.disabled}
         activeClassName='active'>

<NavLink exact to={'/dashboard/accounts'}
         disabled={this.props.item.disabled}
         activeClassName='active'>

URL 发生变化,但视图不变。然而,当我刷新页面或手动转到该 URL 时,它确实会发生变化。


您还可以使用:

import { withRouter } from 'react-router-dom';

然后在导出默认值上,您可以这样做:

export default withRouter(connect(mapStateToProps, {})(Layout));

因为当您有导出连接时,您需要告知该组件将使用路由器。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

React router 4 不会更新链接上的视图,但会在刷新时更新 的相关文章

随机推荐