我正在使用 react-router-dom-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>
我尝试了 onenter on route ,但它不起作用。
在React-Router V4中删除了Ententer,可在React-Router V3中使用。
您可以尝试使用要导航到的组件的组件Willmount功能。
希望这对您有帮助。