首页 > 解决方案 > 如何使反应登录按钮呈现登录组件

问题描述

//This code renders a homepage with login button and signup button.

//我希望登录按钮在单击时呈现登录组件。相同的注册按钮 import React from "react" import "./firstpage.css"

function Firstview(){
    return <div>
        <h1>JC</h1>
        <div className="d-flex justify-content-center">
            <button type="button" className="btn btn-primary btn-lg" >Login</button></div>
            <div className="d-flex justify-content-center">
            <button type="button" className="btn btn-primary btn-lg">Signup</button>
    </div>
  </div>
}
export default Firstview;

标签: reactjsonclick

解决方案


您想使用React Router登录组件的魔力并设置路由。

<Route path="/login" component={Login} />

示例小提琴在这里


推荐阅读