由于您将TopicDetails导出为默认导出,因此可以像
import TopicDetails from './TopicDetails'; //here specify the correct path of TopicDetails functional component
完整的代码在这里
import TopicDetails from './TopicDetails';
class Topics extends React.Component {
constructor(props){
super(props);
this.state ={
url:props.match.url,
path:props.match.path
}
}
render(){
return (<div>
<h2>Topic</h2>
<ul>
{topics.map(({ name, id }) => (
<li key={id}>
<Link to={`${this.state.url}/${id}`}>{name}</Link>
</li>
))}
</ul>
<Route path={`${this.state.path}/:topicId`} component={TopicDetails}/>
</div>)
}
}