如何使用“react-router-dom”中的“Link”使“div”标签可点击?

hon*_*boy 0 html javascript reactjs react-router-dom

我有以下代码:

import React, { Component } from 'react';
import '../styles/CountryDetails.css';
import { Link } from 'react-router-dom';
import { IconContext } from 'react-icons';
import { GoArrowRight } from 'react-icons/go';
import { FaPlane } from 'react-icons/fa';

class CountryDetails extends Component {
    constructor(props) {
        super(props);
        this.state = {
            countryData: props.countryData
        }
    }

    render() {
        console.log(this.state.countryData);
        return (
            <div>
                <h1 className="display-3 text-center my-5">{this.state.countryData.countryClassification}</h1>
                    <div className="CountryDetail">

                        <div className="cards shadow-1 container">
                            <div className="row vertical-align">
                                <div className="col-2 text-center">
                                    <IconContext.Provider value={{ color: '#A9A9A9', className: 'icon-hover icon-size'}}>
                                        <div>
                                            <FaPlane />
                                        </div>
                                    </IconContext.Provider>
                                </div>
                                <div className="col-8">
                                    <h4>Airfare | Car Rental | Hotel Booking Site</h4>
                                    {this.state.countryData.topAirfareCarRentalHotelBookingSite1 ? null : <span className="category-status">Under Construction...</span>}
                                </div>
                                <div className="col-2 text-center">
                                    <IconContext.Provider value={{ className: 'show-hover icon-arrow-size'}}>
                                        <div>
                                            <GoArrowRight />
                                        </div>
                                    </IconContext.Provider>
                                </div>
                            </div>
                            <Link to={`/country/${this.state.countryData.countryAndTerriority}/topAirfareCarRentalHotelBookingSite1`} />
                        </div>
                    </div>
            </div>
        )
    }
}

export default CountryDetails;
Run Code Online (Sandbox Code Playgroud)

这就是我得到的:

在此处输入图片说明

现在,我的 URL 链接显示http://localhost:8080/country/Afghanistan/. 当我点击矩形框时,我希望我的 URL 链接更新为http://localhost:8080/country/Afghanistan/topAirfareCarRentalHotelBookingSite1,它会显示一个不同的组件。

出于某种原因,我无法使这个 div 可点击,并且当我点击它时 URL 不会改变。我是否使用此代码

<Link to={`/country/${this.state.countryData.countryAndTerriority}/topAirfareCarRentalHotelBookingSite1`} />
Run Code Online (Sandbox Code Playgroud)

错了还是放错了地方?

EL-*_*ach 8

你有没有试过把 div 放在链接里?

<Link to = "yourURL" >
   <div></div>
</Link>
Run Code Online (Sandbox Code Playgroud)