I am trying to pass props from one component to another via react-router.When I try to get that props from child component, I got this message TypeError: this.props.params.appState is undefined . Here is my code:
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);
}
.....
change this
this.props.params.appState
to
this.props.route.appState
Params is dynamic segments of the URL, for props you need route
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With