# react-router v6 에서 일치하는 경로를 찾는 방법

v5에서 쓰던 `<Switch>`  컴포넌트를 `<Routes>` 로 변경했다.

어떤 방법으로 적당한 경로를 찾아오는지 궁금해서 찾아보았다.

[https://velog.io/@peacesong/react-router-v6](https://velog.io/@peacesong/react-router-v6) 

[react-router v6 변경점 정리](https://velog.io/@peacesong/react-router-v6)

요약하면,

v5 이전( `<Switch>` )에서는 위에서부터 아래로 탐색하며 일치하는 라우트를 확인하고

v6 ( `<Routes>` )부터는 전체 목록 중 가장 적당한 라우트를 찾아준다고 한다.

그럼 매치되는 라우트가 많으면? 궁금해서 확인해보니 아래와같이 동작한다

![Image](https://upload.cafenono.com/image/slashpagePost/20231101/162252_VawhVN8sEGPdpuGn1E?q=75&s=1280x180&t=outside&f=webp)

- 일치하는 라우트가 둘 이상인 경우: 위쪽 컴포넌트를 반환

![Image](https://upload.cafenono.com/image/slashpagePost/20231101/162238_zg0UxhMJtWEccXWsVD?q=75&s=1280x180&t=outside&f=webp)

- exact match 우선 반환

![Image](https://upload.cafenono.com/image/slashpagePost/20231101/162401_KfbbNagRV99utYdZmu?q=75&s=1280x180&t=outside&f=webp)

For the site tree, see the [root Markdown](https://slashpage.com/brad.md).
