Is it possible to route a component from another component?
So normally it would be done like below
<NavLink to="/link">link</NavLink>
<NavLink to="/anotherLink">link </NavLink>
<Switch>
<Route exact path="/link" component={linkComponent}/>
<Route path="/anotherLink" component={anotherLinkComponent}/>
</Switch>
but is it possible to have NavLink in one component which is loaded in the main component then route from the main component? So have NavLink
in one component and have Route
in the main component.
The Nav component
export default class Nav extends Component {
render() {
return (
<nav className="navigation">
<ul className="nav-container">
<li>
<NavLink to="/" className="nav-title">
First Page
</NavLink>
</li>
<li>
<NavLink to="second-page" className="nav-title">
Second Page
</NavLink>
</li>
<li>
<NavLink to="third-page" className="nav-title">
Third Page
</NavLink>
</li>
</ul>
<div className="nav-decoration">
</div>
</nav>
)
}
}
The App component
import Nav from 'whateverthepath';
export default class App extends Component {
render() {
return (
<div>
<Nav/>
<Switch>
<Route exact path="/" component={Firstpage}/>
<Route path="/secondpage" component={Secondpage}/>
</Switch>
</div>
)
}
}
All the appropriate React imports are done