我在組件跟隨其路由後未呈現組件時遇到了一些問題。路線在父組件Drawings
中創建,並向Drawing
組件發送一些道具。React組件未使用React路由器進行呈現
當我點擊鏈接時,我得到正確的路徑,例如,/drawing/20170724
,我在render
函數中運行的日誌語句。我也獲得了道具,迄今爲止非常好。但是,返回不會發生,所以我需要的HTML不可用。
這裏是Drawings
,其中路線和鏈接的創建:
import React, { Component } from "react";
import { Route, Link } from "react-router-dom";
import AnimatedWrapper from "../modules/AnimatedWrapper";
import Drawing from '../components/Drawing';
class DrawingsComponent extends Component {
render() {
const drawings = this.props.drawings;
const drawingsMap = this.props.drawingsMap;
return(
<div>
<div className="page">
<div className="drawings-list">
{
drawings.map((drawing) => {
return(
<Link to={`/drawing/${drawing.date}`} key={drawing.date}>
<div className="drawing-thumb">
<h2>{drawing.date}</h2>
</div>
</Link>
)
})
}
</div>
{
Object.keys(drawingsMap).map((d, i) => {
return <Route path={`/drawing/${drawings[i].date}`} render={(props) => (<Drawing drawingPkg={drawingsMap[d]} drawingInfo={drawings[i]} {...props} />)} key={`${drawings[i].date}`}/>
})}
</div>
</div>
)
}
}
const Drawings = AnimatedWrapper(DrawingsComponent);
export default Drawings;
這裏是Drawing
:
import React, { Component } from 'react';
import AnimatedWrapper from "../modules/AnimatedWrapper";
class DrawingComponent extends Component {
render() {
const drawing = this.props.drawingPkg;
const drawingInfo = this.props.drawingInfo;
console.log('gonna draw now');
return(
<div className="drawing">
<h2 className="drawing-title">{drawingInfo.title}</h2>
<canvas></canvas>
</div>
)
}
}
const Drawing = AnimatedWrapper(DrawingComponent);
export default Drawing;
我想不通爲什麼繪圖組件沒有返回。
控制檯錯誤將幫助他人更快地瞭解您的情況?請幫忙提供。 – thelonglqd
我很抱歉,沒有控制檯錯誤 - 一切似乎運行良好。我在控制檯中點擊鏈接和'DrawingComponent'日誌'現在繪製'的日誌語句,但是返回語句永遠不會運行,因爲應該返回的HTML不存在於DOM中。 – alightedlamp