My app is something like below, I have a two components - App
and Home
I can go from App to Home, but in the Home
component there are two other routes - Profile
and Quotes
.
On clicking the links for profile and quotes, I don't get any exception, and neither does it load that component.
However if I move the routes to the App
component, then it loads profile
and quotes
just fine.
What could be the issue here. Please guide.
The App component is below -
import React from 'react';
import { Route, Link, Switch } from 'react-router-dom'
class App extends React.Component {
state = { //...some vals }
render() {
return (
<div>
<Link to='/home'>Home</Link>
<Switch>
<Route exact path='/home' component={Home}/>
</Switch>
</div>
)
}
}
export default App
The Home component is below -
import React, { Fragment } from 'react';
import { Route, Link, Switch } from 'react-router-dom'
import Profile from './Profile';
import Quotes from './Quotes';
class Home extends React.Component {
state = { //...some vals }
render() {
return (
<Fragment>
<Link to='/profile'>Profile</Link>
<Link to='/quotes'>Quotes</Link>
<Switch>
<Route exact path='/profile' component={Profile}/>
<Route exact path='/quotes' component={Quotes}/>
</Switch>
</Fragment>
)
}
}
export default Home
And in the index.js
as below -
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { BrowserRouter } from 'react-router-dom'
ReactDOM.render(
<BrowserRouter><App /></BrowserRouter>,
document.getElementById('root')
);