Answer the question
In order to leave comments, you need to log in
How to define nested routes in React JS?
I'm trying to define nested routes in my app using react-router-dom . Here is what I have:
ReactDOM.render(
<Router>
<Switch>
<Route exact path="/app" component={App} />
<Route path="/smartphones" component={() => <SmartphoneTable smartphones={PHONES} />} />
<Route path="/sign-up" component={SignUpForm} />
<Route component={() => <h1>Not found</h1>} />
</Switch>
</Router>,
document.getElementById('root')
);
class App extends Component {
constructor(props) {
super(props);
this.state = {
welcome: "Fuck you!"
};
}
render() {
const { match } = this.props;
return (
<Container>
<Jumbotron>
<h1>Hello, {this.props.name}, {this.props.age} y.o.!</h1>
<p>{this.state.welcome}</p>
<Switch>
<Route path="/app/clock" component={() => <Clock interval="2000" />} />
<Route path="/app/button" component={() => <ClickButton class="off" label="Press me" />} />
</Switch>
</Jumbotron>
</Container>
);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question