react button onClick redirect page

前端 未结 13 2234
我在风中等你
我在风中等你 2020-12-02 15:19

I am working on web application using React and bootstrap. When it comes to applying button onClick, it takes me hard time to let my page being redirect to another. if afte

13条回答
  •  独厮守ぢ
    2020-12-02 15:43

    If all above methods fails use something like this:

        import React, { Component } from 'react';
        import { Redirect } from "react-router";
        
        export default class Reedirect extends Component {
            state = {
                redirect: false
            }
            redirectHandler = () => {
                this.setState({ redirect: true })
                this.renderRedirect();
            }
            renderRedirect = () => {
                if (this.state.redirect) {
                    return 
                }
            }
            render() {
                return (
                    <>
                        
                        {this.renderRedirect()}
                    
                )
            }
        }
    

提交回复
热议问题