D
D
DeVit02022-03-12 23:37:15
React
DeVit0, 2022-03-12 23:37:15

Why is routing not working?

I'm learning React and ran into a routing problem on the site. For some reason it just refuses to work. There is an About.jsx file:

import React from 'react';

const About = () => {
    return (
        <h1>
            Это приложение создано в качестве обучения
        </h1>
    );
};

export default About;

And there is an App.js file where the routing is done directly:

import About from "./pages/About";
function App() {
    return (
        <BrowserRouter>
            <Route path="/about">
                <About/>
            </Route>
        </BrowserRouter>
    )
}

export default App;

At the output I get nothing, an empty sheet. What could be the problem?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexandroppolus, 2022-03-12
@DeVit0

<Route path="/about" element={< About />} />

D
DeVit0, 2022-03-13
@DeVit0

Friends, thank you all! Solved the problem like this:

import React from "react";
import './styles/App.css'
import {BrowserRouter, Route, Router, Routes} from "react-router-dom";
import About from "./pages/About";
import Posts from "./pages/Posts";


function App() {
    return (
        <BrowserRouter>
            <Routes>
                <Route path="/about" element={<About />} />
                <Route path="/posts" element={<Posts />} />
            </Routes>
        </BrowserRouter>
    );
}

export default App;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question