0
基本上,我拖延了導航。有沒有辦法從功能內點擊導航?
單擊鏈接後,onClick處理程序通過檢查條件並調用另一個函數來阻止導航。如果滿足某些條件,則只有該頁面導航到另一個。
那麼如何觸發導航功能內的Navlink點擊。
基本上,我拖延了導航。有沒有辦法從功能內點擊導航?
單擊鏈接後,onClick處理程序通過檢查條件並調用另一個函數來阻止導航。如果滿足某些條件,則只有該頁面導航到另一個。
那麼如何觸發導航功能內的Navlink點擊。
除了使用react-router鏈接組件,您可以使用它們的API以編程方式導航到另一個頁面(如果滿足某些條件)。在官方文件
export default class MyComponent extends Component {
navCheck(nextPage) {
if (someCondition) {
this.context.router.history.push(nextPage);
}
}
render() {
return(<a onClick={() => this.navCheck('/next-page')}>Navigate To Another Page</a>);
}
}
MyComponent.contextTypes = {
router: PropTypes.shape({
history: PropTypes.object.isRequired,
}),
};
的更多信息:https://reacttraining.com/react-router/web/api/history