나는 어떤 콘텐츠를 표시하는 MainContainer
이라는 반응 클래스가 있습니다. 그것에는 많은 링크를 나열하는 자식 인 SidebarContainer
이 있습니다. 내 주요 컨테이너를 렌더링하고, URL에는 PARAM 값이없는 경우 기본적으로 대체로 하나의 기본 ID를 사용하여 콘텐츠의 첫 번째 조각을로드 :반응 라우터에서 동일한 구성 요소를 두 번 다시 사용
var MainContainer = React.createClass({
getInitialState: function() {
return {
selectedContent: this.props.params.slug || 1
},
componentWillReceiveProps: function(nextProps, nextState) {
this.setState({
selectedContent: this.props.params.slug || 1
});
},
}
SidebarContainer 구성 요소는 링크 선택이 있습니다
가<Link to={content.slug}>
{content.title}
</Link>
링크를 클릭하면 브라우저의 URL이 눈에 띄게 바뀌지 만 그 외에는 아무 것도 발생하지 않습니다. 다시 클릭하면 올바른 콘텐츠가 렌더링됩니다. 그러나 지정된 매개 변수를 사용하여 URL을 복사하여 붙여 넣을 때 올바른 내용을 처음으로 렌더링합니다.
ReactDOM.render((
<Router>
<Route path="/" component={MainContainer}/>
<Route path="/content/:slug" component={MainContainer}/>
</Router>
), document.getElementById('react-app'));
내가 잘못 componentWillReceiveProps
수명주기 방법을 사용하고 있습니까 :
내 ReactDOM 렌더링 방법은 다음과 같은 반응 라우터의 설정을 가지고?
옙 그게 내가 누락되었습니다. – Simpleton