function ArticleList() {
// get the parent url and the matched path
let { path, url } = useRouteMatch();
return (
<div>
<h2>Articles</h2>
<ul>
<li>
<Link to={`${url}/pointer`}>C with pointer</Link>
</li>
<li>
<Link to={`${url}/basics`}>C basics</Link>
</li>
</ul>
<Switch>
<Route exact path={path}>
<h3>Please select an article.</h3>
</Route>
<Route path={`${path}/:article`}>
<Article />
</Route>
</Switch>
</div>
);
}
function Article() {
let { article } = useParams();
return (
<div>
<h3>The select article is {article}</h3>
</div>
);
}
Function component
Use RouteMatch() to get the parent URL and the matched path. Use Article() to get the value of article.
0 Comments
Add Comment
Log in to add a comment