我正在使用react-router-dom v4,想在点击链接导航/路由变更后执行回调函数。
<nav>
<ul>
{this.routes.map((route) => <li key={route.id}><Link to={route.path} >{route.title}</Link></li>)}
</ul>
</nav>
<main>
{this.routes.map((route) =>
<Route
key={route.id}
path={route.path}
onEnter={() = > console.log('callback after route change')}
exact
component={route.component} />
)}
</main>
我尝试在Route上使用onEnter,但它不起作用。
componentWillMount
已被弃用 https://reactjs.org/docs/react-component.html#unsafe_componentwillmount - UjinT34