API 호출을 할 때 redux-saga 내의 this.props.location.pathname
에 액세스하는 것이 최종 목표입니다. 여기에 내 현재 작업 솔루션, 비록 오류를 일으키는 반응. 내 코드베이스로 mxstbr/react-boilerplate-brand
을 사용하고 있습니다.redux-saga에서 props.location 객체에 액세스
내 랩핑 구성 요소에 App
, 내 렌더링 메서드에 다음 줄이 있습니다.
render() {
this.props.onUpdateLocation(this.props.location)
}
내 mapDispatchToProps
에는 다음과 같은 내용이 있습니다. 기본적으로 난 그냥 반작용 가게에 this.props.location
을 절약 해요 : 내 redux-saga
내부
function mapDispatchToProps(dispatch) {
return {
onUpdateLocation: (location) => {
dispatch(updateLocation(location));
},
dispatch,
};
}
나는 상태에서 위치에 액세스 할 필요로 그냥 사용; 그러나 여기에 React raises라는 오류가 있습니다.
warning.js:44 Warning: setState(...): Cannot update during an existing state transition (such as within `render` or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to `componentWillMount`.
응용 프로그램이 시작될 때 한 번만 트리거됩니다 때문에 componentWillMount
에 넣을 수없고, this.props.location
가 render
방법으로 업데이트되는 때문에 componentWillUpdate
에 넣어 수 없습니다. 너무 늦기 때문에 나는 그것을 componentDidUpdate
에 넣을 수 없다.
내 redux-saga 내부의 반응 라우터 위치에 쉽게 접근 할 수있는 방법이 없습니까? 만약 <Route path='profile' component={ Profile } />
있는 경우
마지막으로이 문제를 공격하고'ownProps'의 경로 정보에 액세스 할 수있는 동안 결과는 실제 경로가 아닌 일치하는 표현식입니다. 나는. '/ brand/starbucks/details' 대신'/ brand/*/details'를 사용하십시오. –
와일드 카드에'/ brand/: name/details'라는 이름을 붙이십시오. – igl
당신은 굉장합니다! 나는 redux-saga 내에서이 매개 변수에 액세스하는 궁극적 인 해결책을 게시 할 것입니다. –