last day (15 days later) » 

15:24
0
Q: Render Child Component based on route param

EmoI have a react router implemented as such: ReactDOM.render(( <Router history={createBrowserHistory()}> <Route path="/" component={App}> <IndexRoute component={IndexPage} /> <Route name="listView" path="things" component={ThingsList}> <Route name="expandedView" path=":_i...

which version of React Router are you using? I recommend upgrading to the 1.0 final. Named routes are gone in 1.0
Emo
Emo
oops, actually it's v1.0. The name I gave just as reference. But how would you fix it?
I would use the location which is on the context
Emo
Emo
You mean like: this.context.location? It logs undefined on the console.
you need to specify it first: YourComponent.contextTypes = { location: React.PropTypes.object }
Emo
Emo
15:24
Hmm. Now I receive the location object. Thanks! How can I get the param? I receive the hash field but its value is the full path. I need to get the id.
sorry I thought you want to grab the pathname, the params can be found in the props: this.props.params.id
yo
Emo
Emo
Yo!
:) I actually want to grab which router it is so I can conditionally load extra data of the relevant object I have that matches the param
I thought you would just grab the pathname to do that
Emo
Emo
But the pathname is insufficient. It's too large text... :/
And I tried the this.props.params.id as well. It says: "Cannot read property '_id' of undefined"
can I see your component?
Emo
Emo
15:28
It's big :D
do you get anything from this.props ?
just console.log(this.props)
Emo
Emo
yes I get my other props
do you get params in there?
Emo
Emo
nop
Version of router I use is 1.0...
not the latest 1.3..
the latest is 1.0 final
Emo
Emo
15:32
aha ok, I mixed up then..
it's where I play around with Router
and try adding props.params on the Inbox for example
you will get them there
hard to tell without seeing the code
Emo
Emo
OK, I'll check it out. Thanks!
let me know if you still have issues
we are all on the Discord in the Reactiflux

  last day (15 days later) »