Home > Net >  React router dom renders a blank page
React router dom renders a blank page

Time:03-28

I am new to react-router-dom for the first time . I am using react-router-dom to switch between pages and it is rendering a blank page, only the navbar component is rendering. When I render the home and auth components individually outside the Routes, they render successfully.Please help me debugging this code.

Here is my App.js

import React from 'react';
import { Container } from '@material-ui/core';
import { BrowserRouter , Route , Routes } from 'react-router-dom'

import Home from './components/Home/Home';
import Navbar from './components/Navbar/Navbar';
import Auth from './components/Auth/Auth';

const App = () => (
  <BrowserRouter>
    <Container maxWidth="lg">
      <Navbar />
      {/* <Home/>
      <Auth/> */}
      <Routes>
        <Route exact path="/"  component={Home} />
        <Route exact path="/auth"  component={Auth} />
      </Routes>
    </Container>
  </BrowserRouter>
);

export default App;

Here is my package.json

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://localhost:5000/",
  "dependencies": {
    "@material-ui/core": "^4.12.3",
    "@material-ui/icons": "^4.11.2",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "axios": "^0.19.2",
    "moment": "^2.27.0",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-file-base64": "^1.0.3",
    "react-google-login": "^5.2.2",
    "react-redux": "^7.2.6",
    "react-router-dom": "^6.2.2",
    "react-scripts": "3.4.1",
    "redux": "^4.0.5",
    "redux-thunk": "^2.3.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "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-config-airbnb": "^18.2.0",
    "eslint-plugin-import": "^2.22.0",
    "eslint-plugin-jsx-a11y": "^6.3.1",
    "eslint-plugin-react": "^7.20.6",
    "eslint-plugin-react-hooks": "^4.1.0"
  }
}


CodePudding user response:

it's element not component

<BrowserRouter>
    <Container maxWidth="lg">
      <Navbar />
      {/* <Home/>
      <Auth/> */}
      <Routes>
        <Route exact path="/" element={Home} />
        <Route exact path="/auth" element={Auth} />
        <Route path="*" element={<Navigate to="/" />} />
      </Routes>
    </Container>
  </BrowserRouter>
  • Related