Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
BrowserRouter in React leading to "invalid hook calls"

I'm new to React, and I'm trying to set up paths using BrowserRouter, Route and Routes. Thus far, my code looks like the following

import React from "react"
import "./App.css";
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import Login from "./Login";

function App() {

    return (
    <div className="App">
        <h1>App page</h1>
        <Router>
            <Routes>
                <Route exact path="/login">
                     <Login />
                </Route>
            </Routes>
        </Router>
    </div>
  )
}

export default App

However, nothing's appearing on the browser page - the console output looks like the following error message in console log

The error seems to be with the router bits, since when I take those lines out, things in the h1 tag seem to be printing fine. Would you know how to fix this/what might be causing this?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Login is not a <Route> component. All component children of <Routes> must be a <Route>or <React.Fragment>.

try this:

import React from "react"
import "./App.css";
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import Login from "./Login";

function App() {

    return (
    <div className="App">
        <h1>App page</h1>
        <Router>
            <Routes>
                <Route exact path="/login" element={<Login />}/>
            </Routes>
        </Router>
    </div>
  )
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!