에러 노트

[React] Matched leaf route at location "/"

2021bong 2021. 12. 3. 22:35

리액트 라우터를 사용해서 컴포넌트를 불러오는데 이렇게 쓰니까 오류가 남

<Route path="/rock-scissors-paper" component={RSP}/>
--------------------------------------------------------------
Matched leaf route at location "/rock-scissors-paper" does not have an element.

Matched leaf route at location "/rock-scissors-paper" does not have an element.

해당 위치에 일치하는 엘리먼트가 없다


<Route path="/rock-scissors-paper" element={<RSP />} />

component를 element로 고쳐서 입력하면 잘 작동함


react-router-dom버전이 6인지 5인지 확인해볼것!

6이면 component가 사용이 안되서 위 방법대로 element를 써야하는 것 같음

5이면 component 사용 가능!

npm i react-router-dom@5.3.0 으로 설치하면 됨!

 

참고

https://stackoverflow.com/questions/69854011/matched-leaf-route-at-location-does-not-have-an-element

 

Matched leaf route at location "/" does not have an element

Matched leaf route at location "/" does not have an element. This means it will render an with a null value by default resulting in an "empty" page //App.js File import {

stackoverflow.com

 

댓글 확인

https://www.youtube.com/watch?v=veXqpfcis0A&list=PLcqDmjxt30RtqbStQqk-eYMK8N-1SYIFn&index=64 

 

728x90