내 경로 코드는 다음과 같습니다 중첩 된 경로 제대로 이미지를로드하지 않습니다 반작용 :는 라우터가
<Router history={browserHistory}>
<Route path='/' component={AppContainer}>
<IndexRoute component={Home}/>
<Route path='/MyRYLA' component={MyRYLA} />
<Route path='/gallery' component={PhotoViewer}/>
<Route path='/about' component={AboutView}>
<IndexRoute component={AboutRYLA}/>
<Route path='/about/contact' component={Contact}/>
<Route path='/about/directions' component={Directions}/>
<Route path='/about/principles' component={Principles}/>
<Route path='/about/faq' component={FAQ}/>
</Route>
</Route>
</Router>
내가 AboutView
아래의 각 페이지는 여전히에 해당 이미지를 가질 수 있도록, AboutView
내에서 렌더링 이미지를 가지고있다. 그러나 browserHistory.push('/about/directions')
을 사용하여 '/ about/directions'와 같은 중첩 된 URL을 탐색 할 때마다 이미지가로드되지 않습니다. 그러나 browserHistory.push('/about')
을 사용하여 '/ about'로 이동하면 이미지가로드됩니다.
GET http://localhost:8080/about/af16977b21bb178d3bb328689d1ecd65.jpg 404 (Not Found)
이라는 콘솔에 오류가 표시됩니다. 이것은 존재하지 않는 'about'디렉토리에서 이미지를 얻으려는 것처럼 보입니다. 이미지를로드하고 React-Router가 존재하지 않는 'about'디렉토리를 통해이 이미지에 액세스하는 것을 방지하려면 어떻게해야합니까?
필자는 require ('../../resources/ryla.jpg'); – jrademacher
다른 파일의 구성 요소/페이지가 디렉토리 안에 있습니까? 당신도 그것들에서 요구해야 할 것입니다, 나는 당신이 그것을하고 있지만, 같은 길을 가고 있다고 생각합니까? ../../../resources/ryla.jpg로 변경해야합니다. – Martina