헤더 또는 정적 콘텐츠와 같은 모든 경로에서 무언가를 렌더링 할 수 있도록 내 경로를 래핑하려고합니다. 나는이 게시물을 여기에서 보았다 : Nested Routes in React Router v4 나는 거기에서 가지고있는 것처럼 나의 길을 감쌌다. 그러나 보여주는 유일한 물건은 포장 구성 요소 다.React Router 4의 중첩 경로 (구성 요소에서 시도한 포장 경로)
그래서 보여주는 유일한 것은 /
및 /dashboard
노선이다 :
포장 경로 :
<Home>
<Switch>
<Route path="/dashboard" component={Layout} />
<Route component={NotFound} />
</Switch>
</Home>
홈 구성 요소 :
다음Home Component
Dashboard
코드입니다
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
class Home extends Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<h2>Home component</h2>
<Link to="/dashboard">Dashboard</Link>
</div>
);
}
}
export default Home;
레이아웃 구성 요소 :
import React, { Component } from 'react';
class Layout extends Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<h2>Layout Component</h2>
<h2>Layout Component</h2>
</div>
);
}
}
export default Layout;
잘 작동합니다! 고맙습니다 –