I've got a pretty standard setup, a router with pages:
import React from "react";
import ReactDOM from "react-dom";
import { IndexRoute, Router, Route, Link, hashHistory as history } from "react-router";
import Layout from "./pages/Layout";
...
import User from "./pages/User";
ReactDOM.render(
<Router history={history}>
<Route path="/" component={Layout}>
<IndexRoute component={...}/>
<Route path="project/create" component={...}/>
<Route path="project/:id" component={...}/>
<Route path="user/:id" component={User}/>
<Route path="*" component={...}/>
</Route>
</Router>,
document.getElementById("app-root"));
Everything is working perfectly except when I go to a page like site.tld/#/user/5
. The User
component has some trouble getting instantiated properly. All other pages are working, I also have another page that uses url parameters (project/:id
) and it is working fine as well.
import React from "react";
...
export default class User extends React.Component {
constructor() {
super();
console.log(this);
...
}
render() {
return ...
}
This is what I get in the console.
I'm sure it's the dumbest thing ever again, but I can't pick it out...
this.props
in therender()
method to verify. – Hunter McMillen Mar 17 '17 at 13:21this.props
but you DO have theprops
available as the first argument to the constructor. Simply pass this object around to whatever function or logic you're trying to come up with maybe? – ZekeDroid Mar 17 '17 at 15:21