3
リア・ルータ経由であるコンポーネントから別のコンポーネントに小道具を渡そうとしています。子コンポーネントからその小道具を手に入れようとすると、私はこのメッセージを受け取りましたTypeError: this.props.params.appState is undefined
。ここに私のコードは次のとおりです。リアクション小道具が定義されていません
Tracks.jsx:
import { observable } from 'mobx';
export default class Tracks {
@observable tracks = [];
}
app.jsx:
.......
import Tracks from './store/Tracks.jsx';
......
const appState = new Tracks();
ReactDOM.render(
<Router history={browserHistory} >
<Route path="/" component={Login} />
<Route path="/dashboard" onEnter={authRequired} component={Main}>
<Route path="album/create" component={AlbumCreate} />
<Route path="album/:id" component={Album} appState={appState}/>
<Route path="album/:id/upload" component={Upload} />
</Route>
</Router>,
document.getElementById('app')
);
Album.jsx:
.....
@observer
export default class Album extends React.Component {
constructor(props) {
super(props);
}
componentDidMount() {
console.log(this.props.params.appState.tracks);
}
.....
を必要と小道具は、あなたが 'this.props'含まれているかどうか確認する可能性があるため、URLの動的なセグメントのですか? –
エラーが表示されるので、 '' TypeError:this.props.params.appStateは未定義です.''なので、 '' appState''は '' undefined''それ自体は '' this.props''ではないようです。 – Kamil
@MarioAlexandroSantini 'オブジェクト{履歴:オブジェクト、場所:オブジェクト、パラメータ:オブジェクト、ルート:オブジェクト、ルートパラメータ:オブジェクト、ルート:配列[2]、子:null、2その他...}' – pyprism