Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

javascript - react按钮onClick重定向页面(react button onClick redirect page)

I am working on web application using React and bootstrap.(我正在使用React和bootstrap开发Web应用程序。)

When it comes to applying button onClick, it takes me hard time to let my page being redirect to another.(当应用按钮onClick时,我很难让我的页面重定向到另一个页面。) if after a href , I cannot go the another page.(如果在href之后,我无法进入另一个页面。) So would you please tell me is there any need for using react-navigation or other to navigate the page using Button onClick ?(所以,请您告诉我是否有必要使用React-navigation或其他通过Button onClick来导航页面?) import React, { Component } from 'react'; import { Button, Card, CardBody, CardGroup, Col, Container, Input, InputGroup, InputGroupAddon, InputGroupText, Row, NavLink } from 'reactstrap'; class LoginLayout extends Component { render() { return ( <div className="app flex-row align-items-center"> <Container> ... <Row> <Col xs="6"> <Button color="primary" className="px-4"> Login </Button> </Col> <Col xs="6" className="text-right"> <Button color="link" className="px-0">Forgot password?</Button> </Col> </Row> ... </Container> </div> ); } }   ask by Raju yourPepe translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

use React Router v4:(使用React Router v4:)

import { withRouter } from 'react-router-dom'; import { Button, Card, CardBody, CardGroup, Col, Container, Input, InputGroup, InputGroupAddon, InputGroupText, Row, NavLink } from 'reactstrap'; class LoginLayout extends Component { constuctor() { this.routeChange = this.routeChange.bind(this); } routeChange() { let path = `newPath`; this.props.history.push(path); } render() { return ( <div className="app flex-row align-items-center"> <Container> ... <Row> <Col xs="6"> <Button color="primary" className="px-4" onClick={this.routeChange} > Login </Button> </Col> <Col xs="6" className="text-right"> <Button color="link" className="px-0">Forgot password?</Button> </Col> </Row> ... </Container> </div> ); } } export default withRouter(LoginLayout);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...