it-source

React-Router : IndexRoute의 목적은 무엇입니까?

criticalcode 2023. 3. 2. 22:18
반응형

React-Router : IndexRoute의 목적은 무엇입니까?

IndexRouteIndexLink를 사용하는 목적이 무엇인지 모르겠습니다.어떤 경우에도 About 경로가 활성화되지 않았다면 아래 코드는 Home 컴포넌트를 먼저 선택했을 것으로 보입니다.

<Route path="/" component={App}>
  <IndexRoute component={Home}/>
  <Route path="about" component={About}/>
</Route>

<Route path="/" component={App}>
  <Route path="home" component={Home}/>
  <Route path="about" component={About}/>
</Route>

첫 번째 케이스의 장점/목적은 무엇입니까?

위의 예에서는,/할 수 있다App와 함께Home어렸을 때 지나갔죠.아래 예에서는 로 이동합니다./할 수 있다App 다 없이 Home도 아니다About둘 다 일치하지 않기 때문에 렌더링되고 있습니다.

이전 버전의 React Router의 경우 관련 버전의 Index Routes and Index Links 페이지에서 자세한 내용을 확인할 수 있습니다.버전 4.0 이후로는 리액트라우터는IndexRoute같은 목표를 달성하기 위한 추상화.

언급URL : https://stackoverflow.com/questions/32706913/react-router-what-is-the-purpose-of-indexroute

반응형