我正在寻找有关如何向我的reactjs应用程序添加后退按钮的示例或帮助...当我单击导航栏上的“返回”时,以下引发此错误
interface IToolPanel {
// The init(params) method is called on the tool panel once upon component initialisation.
init(params: IToolPanelParams): void;
// Returns the GUI for this Tool Panel and can be a string of html or a DOM element.
getGui(): any;
// Can be left blank if no custom refresh logic is required.
refresh(): void;
}
TypeError: Cannot read property 'goBack' of undefined
答案 0 :(得分:0)
如果使用react-router-dom,则可以使用this.props.history.goBack()
方法,这使您退后一步。了解有关history
答案 1 :(得分:0)
您可以使用this.props.history.goBack
export default class Navbar extends Component {
constructor(props) {
super(props);
}
goBack = () => {
this.props.history.goBack();
}
render() {
return (
<Navbar default collapseOnSelect>
<Navbar.Header>
<Navbar.Brand>
My App
</Navbar.Brand>
<Navbar.Toggle />
</Navbar.Header>
<Navbar.Collapse>
<Nav pullRight>
<NavItem eventKey={1} href="https://app.com">
Home
</NavItem>
<NavItem onClick={this.goBack} />
</Nav>
</Navbar.Collapse>
</Navbar>
)
}
}