1 回答

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊
我猜你正在使用React Router作為你的路由解決方案。我不確定在它周圍包裝一個(gè)實(shí)用函數(shù)會(huì)有多大用處,因?yàn)樗呀?jīng)是一個(gè)實(shí)用函數(shù)。但是,如果您想這樣做,則需要將當(dāng)前history對(duì)象公開給函數(shù)。像這樣的東西:
const NavigationService = {
redirectView = (history, view) => {
history.push(`/${view}`)
}
}
const MyComponent = withRouter(({ history }) => (
<BtnRectangularBorder>
<BtnRectangular
className="battle-shonen-color btn-rectangular-md-size btn-rectangular-primary"
title="Cards Overview"
onClick={NavigationService.redirectView(history, "/cards-overview")}
/>
</BtnRectangularBorder>
));
通常我只是在實(shí)用程序中包裝東西,但老實(shí)說,我不確定在這種情況下它會(huì)給你帶來什么。希望有幫助。
添加回答
舉報(bào)