我想在中显示标题<;AppBar/>以某种方式从当前路由传入
在React Router v4中,如何<;AppBar/>是否能够将当前路线传递到其标题道具
<;路由器basename='/app'>;
<;main>;
<;菜单活动={Menu}close={this.closeMenu}/>;
<;覆盖活动={menu}onClick={this.closeMenu}/>;
<;AppBar handleMenuIcon={this.handleMenuIcon}title='Test'/>;
<;路由路径='/customers'组件={customers}/>;
</main>;
</路由器>;
是否有方法从上的自定义道具传递自定义标题;路线/>
在react router的5.1版本中,有一个名为useLocation的钩子,它返回当前位置对象。这在您需要知道当前URL的任何时候都可能有用
从'react router dom'导入{useLocation}
函数HeaderView(){
const location=useLocation();
console.log(location.pathname);
返回路径:{location.pathname}<;/span>;
}