티스토리 뷰
1. 오류
A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>
오류 원인 : react-router-dom 버전 6 이상부터는 <Route>를 <Routes>로 감싸줘야한다고 한다.
오류가 발생한 코드
import {BrowserRouter, Route} from 'react-router-dom'
....
function App(){
return (
...
<Route path="/"><Home></Home></Route>
<Route path="/topics"><Topics></Topics></Route>
<Route path="/contact"><Contact></Contact></Route>
...
)
}
오류 해결
: <Routes> 추가
import {BrowserRouter, Route, Routes} from 'react-router-dom'
....
function App(){
return (
...
<Routes>
<Route path="/"><Home></Home></Route>
<Route path="/topics"><Topics></Topics></Route>
<Route path="/contact"><Contact></Contact></Route>
</Routes>
...
)
}
2. 오류
두 번째 오류가 발생함.
Uncaught Error: [Home] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>
오류 원인 : React-router-dom v6부터는 Switch 대신 Routes를 사용하고 Route 안에 component 대신 element 사용한다.
음... 그러니까 Route 태그안에는 component가 있으면 안된다. component를 element로 변경해준다.
아까 첫 번째 오류 해결한 코드가 두 번째 오류 발생 코드이다.
오류 해결
: element 사용
import {BrowserRouter, Route, Routes} from 'react-router-dom'
....
function App(){
return (
...
<Routes>
<Route path="/" elemenet={<Home />}></Route>
<Route path="/topics" elemenet={<Topics />}></Route>
<Route path="/contact" elemenet={<Contact />}></Route>
</Routes>
...
)
}
끝-
반응형
LIST
'React' 카테고리의 다른 글
| typescript compiler : tsc -v 보안오류발생 (0) | 2023.09.22 |
|---|
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 터틀그래픽
- JAVA오류해결
- Turtle Graphic
- 다인승탑승
- Kkma
- 오븐시계
- 에러발생
- 파이썬
- 사람검출
- yolov8
- 터틀그래픽예제
- randrange
- UnsupportedClassVersionError
- 10828번
- 백준
- streamlistener
- baekjoon
- database연결
- 다인승
- 사람수세기
- konlpy
- gradleload오류
- SPRING오류해결
- randint
- 문제풀이
- springboot
- python공부
- YOLO
- tweepy
- 터틀그래픽 명령어
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
글 보관함
반응형