React设置⽹页title
我们可以通过listen监听数据的变化
1)需要在引⼊路由的时候引⼊withRouter
import { Switch, Route, NavLink, Redirect, withRouter } from'react-router-dom';
在暴露的地⽅吧根组件包裹起来
export default withRouter( App);
2)在constructor中this.props.history.listen中执⾏location.pathname能够观察到路由的变化constructor(props) {
super(props);
console.log( 'app', this.props .history)
this.props .history .listen(( location) =>{
console.log(location .pathname)
switch(location .pathname){
case'/list':
document.title ="列表";
break;
case'/items':
document.title ="内容";
break;
case'/list/users':
document.title ="⽤户";
break;
case'/list/companies':
document.title ="公司";
break;
default: break;
}
})react组件之间通信
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。