Uncaught Error: useRoutes() may be used only in the context of a <Router> component.
index.js 파일에 BrowserRouter를 빼먹어서 난 오류.
import 먼저 해주고
import { BrowserRouter } from 'react-router-dom';
<App/ > 태그를 <BrowserRouter> 태그로 감싸줬더니 화면이 잘 뜬다.
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { BrowserRouter } from 'react-router-dom';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<BrowserRouter>
<React.StrictMode>
<App />
</React.StrictMode>
</BrowserRouter>
);
App.js
import React from "react";
import { Route, Routes } from "react-router-dom";
import Test from "./pages/Test";
import './App.css';
function App() {
return (
<div className="App">
<Routes>
<Route path="/" element={<Test />} />
</Routes>
</div>
);
}
export default App;