Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlex Maguey
Courses Plus Student 191 PointsRefactor navigation to its own component
I tried to refactor the courses navigation to its own component but when i use the component i got the following error: Cannot read property 'url' of undefined
import React from 'react';
import {NavLink, Route, Redirect} from 'react-router-dom';
import HTML from './courses/HTML';
import JavaScript from './courses/JavaScript';
import CSS from './courses/CSS';
import Navigation from './courses/navigation';
const Courses = ({match}) => (
<div className="main-content courses">
<div className="course-header group">
<h2>Courses</h2>
<Navigation />
</div>
{/* Write routes here... */}
<Route exact path={match.path} render={()=> <Redirect to={`${match.path}/html`} />} />
<Route path={`${match.path}/html`} component={HTML} />
<Route path={`${match.path}/javascript`} component={JavaScript} />
<Route path={`${match.path}/css`} component={CSS} />
</div>
);
export default Courses;
and the component
import React from 'react'
import {NavLink, Route} from 'react-router-dom'
export default function Navigation({match}) {
return (
<ul className="course-nav">
<li><NavLink to={`${match.url}/html`}>HTML</NavLink></li>
<li><NavLink to={`${match.url}/css`}>CSS</NavLink></li>
<li><NavLink to={`${match.url}/javascript`}>JavaScript</NavLink></li>
</ul>
);
}
1 Answer
Ken Stone
29,703 PointsI'm new to jsx myself but where you have
<Navigation />
I'm not sure but maybe you need to somehow pass in
match
just a wild guess at this point, maybe something to try...