'react-router-dom@6 does not browse and does not display pages
I started a new project and decided to use react-router-dom@6 to navigate between my pages. I did the installation and configuration, but the navigation is not working and I could not find the problem. I need that when accessing "/" the "Home" page is displayed and that when accessing "/profile" the Profile page is displayed. Name at the moment localhost:3000 only displays a blank page like "/home" and "/profile''. I didn't identify the problem.
Index.js
/* eslint-disable react/jsx-filename-extension */
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import './i18n';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root'),
);
reportWebVitals();
App.js
/* eslint-disable react/react-in-jsx-scope */
/* eslint-disable react/jsx-filename-extension */
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import Routes from './routes';
function App() {
return (
<BrowserRouter>
<Routes />
</BrowserRouter>
);
}
export default App;
routes.js
/* eslint-disable linebreak-style */
/* eslint-disable no-unused-vars */
/* eslint-disable linebreak-style */
/* eslint-disable react/react-in-jsx-scope */
/* eslint-disable react/jsx-filename-extension */
/* eslint-disable linebreak-style */
import React from 'react';
import {
Routes,
Route,
} from 'react-router-dom';
import Home from './pages/home';
import Profile from './pages/profile';
function MainRoutes() {
return (
<Routes>
<Route path="/" element={<Home />} />
<Route path="/profile" element={<Profile />} />
</Routes>
);
}
export default MainRoutes;
Home.jsx
/* eslint-disable linebreak-style */
import { useTranslation } from 'react-i18next';
import React from 'react';
const { t } = useTranslation();
function Home() {
return (
<h1>
{t('home.title')}
;
</h1>
);
}
export default Home;
Profile.jsx
/* eslint-disable linebreak-style */
import { useTranslation } from 'react-i18next';
import React from 'react';
const { t } = useTranslation();
function Profile() {
return (
<h1>
{t('home.title')}
;
</h1>
);
}
export default Profile;
package.json
{
"name": "bruno-profile",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.2.1",
"babel-eslint": "^10.1.0",
"i18next": "^21.6.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-i18next": "^11.15.3",
"react-router-dom": "^6.2.1",
"react-scripts": "5.0.0",
"web-vitals": "^2.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"eslint": "^8.8.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0"
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
