Javascript 如何使链接适合其内部的组件? 我所拥有的:

Javascript 如何使链接适合其内部的组件? 我所拥有的:,javascript,css,reactjs,react-router,Javascript,Css,Reactjs,React Router,但是没有起作用 我需要的是: 如何使适合其内容 或者使用该按钮以更好的方式触发 您可以使用下面的flex box样式,也可以简单地制作;宽度:100% .link{ display:flex; flex-flow:row wrap; flex-basis:50%; min-width:50%; line-height:normal; } 就高度而言,如果父.flexbox显示属性为flex,则将自动拾取高度 您可以使用下面的flex box样式,或者简单

但是没有起作用

我需要的是:
  • 如何使
    适合其内容
  • 或者使用该按钮以更好的方式触发

  • 您可以使用下面的flex box样式,也可以简单地制作;宽度:100%

    .link{
        display:flex;
        flex-flow:row wrap;
        flex-basis:50%;
        min-width:50%;
        line-height:normal;
    }
    

    就高度而言,如果父.flexbox显示属性为flex,则将自动拾取高度

    您可以使用下面的flex box样式,或者简单地制作。链接显示:block;宽度:100%

    .link{
        display:flex;
        flex-flow:row wrap;
        flex-basis:50%;
        min-width:50%;
        line-height:normal;
    }
    

    就高度而言,如果父.flexbox显示属性为flex,则将自动拾取高度

    React路由器为组件提供历史道具

    您可以替换链接并在按钮中包含一个onClick

    <div className="flexBox">
        <h4>Rampa de Cores</h4>
        <CustomButton 
          onClick={() => this.props.history.push('/new')} 
          label="Adicionar" 
          className={"addButton"}
        />
    </div>
    
    
    岩芯Rampa
    this.props.history.push('/new')}
    label=“Adicionar”
    className={“addButton”}
    />
    
    React路由器为组件提供历史道具

    您可以替换链接并在按钮中包含一个onClick

    <div className="flexBox">
        <h4>Rampa de Cores</h4>
        <CustomButton 
          onClick={() => this.props.history.push('/new')} 
          label="Adicionar" 
          className={"addButton"}
        />
    </div>
    
    
    岩芯Rampa
    this.props.history.push('/new')}
    label=“Adicionar”
    className={“addButton”}
    />
    
    您不应将按钮用作链接的子项。相反,您可以使用按钮并在单击按钮时触发状态更改或重定向。如果使用react router dom的路由声明了新路由,则可以只使用以下代码:

     <div className="flexBox">
            <h4>Rampa de Cores</h4>
            <Link to={"/new"} className="link">
                <CustomButton label="Adicionar" className={"addButton"}
    onButtonClick={()=>this.props.history.push('/new')}/>
            </Link>
    </div>
      <button
     onClick={this.props.onButtonClick}
    >{this.props.label}</button>
    
    
    岩芯Rampa
    this.props.history.push('/new')}/>
    {this.props.label}
    

    如果当前组件未定义路由,则必须使用
    react router dom
    中的
    withRouter
    来访问历史道具。

    您不应将按钮用作链接的子级。相反,您可以使用按钮并在单击按钮时触发状态更改或重定向。如果使用react router dom的路由声明了新路由,则可以只使用以下代码:

     <div className="flexBox">
            <h4>Rampa de Cores</h4>
            <Link to={"/new"} className="link">
                <CustomButton label="Adicionar" className={"addButton"}
    onButtonClick={()=>this.props.history.push('/new')}/>
            </Link>
    </div>
      <button
     onClick={this.props.onButtonClick}
    >{this.props.label}</button>
    
    
    岩芯Rampa
    this.props.history.push('/new')}/>
    {this.props.label}
    

    如果当前组件未使用路由定义,则必须使用
    react router dom
    中的
    withRouter
    来访问历史记录属性。

    按钮不允许作为链接的子项。您可以尝试使用按钮
    onClick
    。只需使用按钮中的onClick替换链接即可。React Router提供的道具可让您“推”到新的URL按钮不允许作为链接的子项。您可以尝试使用按钮
    onClick
    。只需使用按钮中的onClick替换链接即可。React路由器提供的道具可以让你“推”到一个新的url