ily*_*lyo 42 url reactjs react-router react-router-v4
我使用以下简单的导航代码
<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'>
Run Code Online (Sandbox Code Playgroud)
URL更改但视图不更改.但是,当我刷新页面或手动转到该URL时,它会发生变化.
dam*_*ufe 49
你也可以使用:
import { withRouter } from 'react-router-dom';
Run Code Online (Sandbox Code Playgroud)
然后在导出默认值上,你会这样:
export default withRouter(connect(mapStateToProps, {})(Layout));
Run Code Online (Sandbox Code Playgroud)
因为当你有一个导出连接时,你需要告诉该组件将使用路由器.
Tom*_*zyk 29
这是因为react-redux
connect
方法实现了当props没有改变时shouldComponentUpdate
会导致组件不呈现.现在这与react-router 4相冲突.
为了避免它,你可以传递{pure: false}
到connect
中所述反应,终极版的故障排除部分.
另一种方法是使用withRouter
HOC或传递location
道具,如DOCS中所述.
归档时间: |
|
查看次数: |
19829 次 |
最近记录: |