我想显示title在<AppBar />以某种方式从目前的路线通过。
title
<AppBar />
在React Router v4中,如何将<AppBar />当前路由传递到titleprop中?
<Router basename='/app'> <main> <Menu active={menu} close={this.closeMenu} /> <Overlay active={menu} onClick={this.closeMenu} /> <AppBar handleMenuIcon={this.handleMenuIcon} title='Test' /> <Route path='/customers' component={Customers} /> </main> </Router>
有没有办法通过从自定义自定义标题prop上<Route />?
prop
<Route />
在5.1版本的react-router中,有一个名为 useLocation 的钩子,该钩子返回当前的位置对象。每当您需要知道当前URL时,这可能都会有用。
import { useLocation } from 'react-router-dom' function HeaderView() { let location = useLocation(); console.log(location.pathname); return <span>Path : {location.pathname}</span> }