Home > database >  React router not showing basic web page?
React router not showing basic web page?

Time:02-28

This is my app.js

import React, { Component } from "react";
import { Routes, BrowserRouter } from "react-router-dom";
import { Route } from "react-router";
import Home from "./react.components/Home/Home";

class App extends Component {
  render() {
    return (
      <BrowserRouter>
        <Routes>
          <Route path="/" component={<Home />} exact />
        </Routes>
      </BrowserRouter>
    );
  }
}

export default App;

This is my Home.js from import Home from './react.components/Home/Home'

import React from "react";

class Home extends React.Component {
  render() {
    return (
      <div>
        <h1>Test</h1>
        <h2>hello world</h2>
      </div>
    );
  }
}

export default Home;

Yet when I go on localhost:3000 (where my react server is run) I see an empty page. I'm expecting to say Test and hello world?

enter image description here

How do I fix this?

CodePudding user response:

Suppose your using react-router-dom v6. So you can reference this guide Upgrading from v5

// v4 and v5 before 5.1
<Route path="/" component={<Home />} exact />

// v6
<Route path="/" element={<Home />} />

CodePudding user response:

<Route path="/" component={} exact />

this syntax is not correct

try this

  • Related