TIL
[Context] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>
은지:)
2023. 1. 21. 20:28
728x90
반응형
[Context] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>
Router 컴포넌트에서 났던 오류!
상황
contextAPI를 사용하기 위해
<Context> 컴포넌트를 만들어 코드를 작성하고
전역으로 쓰기 위해 라우터에서 감쌌다 👇
<Routes>안으로 감싸버렸더니 Routes 자식으론 나 <> 밖에 못 받는다는 오류가 나왔다
react-router-dom v6 부터 <switch> 대신 <Routes> 를 쓰는데
오류가 뱉은 그대로
<Routes> 안에는
<Route path ="" element={<컴포넌트/>} />
형태만 자식으로 올 수 있다
해결
<Routes>를 안에 써주었다
728x90
반응형