reactjs - React js中的嵌套路由不起作用
问题描述
我正在研究显示医生列表的项目。我正在尝试如下嵌套路由。当我转到/book-appointment页面时,没有显示任何内容,并且没有显示控制台错误,但没有呈现约会组件。我对嵌套路由感到困惑,我不知道我在这里犯了什么错误
布局.js
<Route path="/" exact component={Sections} />
<Route
path="/doctors"
render={(props) => {
return this.state.doctors_list.map((doctor, index) => {
return (
<Doctors
key={index}
clinic_name={doctor.clinic_name}
doctor_name={doctor.doctor_name}
speciality={doctor.speciality}
feedback={doctor.feedback}
location={doctor.location}
doctor_fee={doctor.doctor_fee}
available_days={doctor.available_days}
available_timing={doctor.available_timing}
rating={doctor.rating_percentage}
votes={doctor.votes}
images={doctor.images}
/>
);
});
}}
/>
医生.js
const Doctors = (props) => (
....
....
<Route
path="/book-appointment"
exact
render={(props) => {
return <Appointment />;
}}
/>
....
....
)
解决方案
我在我的项目中遇到了一些错误,我也创建了未找到的页面,它把我带到了那里所以我很清楚问题出在路线上。
在我的情况下,从父路由中删除确切的问题可以解决问题,因为路由始终相同,但子路由将被更改。路线元素应该是:
<Route path="/" component={Sections} />
<Route
path="/doctors"
render={(props) => {
return this.state.doctors_list.map((doctor, index) => {
return (
<Doctors
key={index}
clinic_name={doctor.clinic_name}
doctor_name={doctor.doctor_name}
speciality={doctor.speciality}
feedback={doctor.feedback}
location={doctor.location}
doctor_fee={doctor.doctor_fee}
available_days={doctor.available_days}
available_timing={doctor.available_timing}
rating={doctor.rating_percentage}
votes={doctor.votes}
images={doctor.images}
/>
);
});
}}
/>
希望这可以帮助。
推荐阅读
- c# - 如何通过 Selenium 在 Chrome 上获取当前活动的标签索引?
- android - 只有最后添加的项目会在 Android 的 Firebase 实时数据库中删除
- gstreamer - 如何合并来自不同来源的音频和视频以制作 kinesis 视频
- python - 当在给定行中找到其中一个值时,使用字典的键作为行值的新 DataFrame 列
- sugarcrm - SugarCRM Rest API set_relationship 在联系人和文档之间
- php - laravel 5.8 自定义用户注册重定向回表单未登录
- aws-api-gateway - 如何通过 Terraform 将 AWS API 网关上的特定路径连接到特定 ECS 实例?
- mysql - 如何优化我的 MySQL 选择查询?
- css - 为什么当我按下刷新时,选择中的下拉箭头会改变外观和移动位置?
- java - Wiremock - 第一次映射错误时重定向到代理