Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React throws Error and Uncaught Error when i use BrowserRouter, how to fix it?

I’m sorry for my inexperience, but I’ve lost my way. I use Browser Router and it gives me the error
" "Error react-doma.production.min.js:216"
and
""react-dot.production.min.js:260 Uncaught Error"
I do not know how to fix it, because I do not even know the error. My code:

App.js

const BaseTemplate = () => (
    <div className="App">
        <BrowserRouter>
            <Routes>
                <Route path="/" exact component={Mainpage}/>
            </Routes>
        </BrowserRouter>
    </div>
);

function App() {
    return (
        <BaseTemplate/>
    );
}

export default App;
Mainpage.js
const localService = new Service();
class Mainpage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            category: '',
        };
    }
    componentDidMount() {
        document.title = 'Catalogs';
        localService.listCategories().then(r => alert(r.data)).catch(e => alert(e.response));
    }

    render() {
        return (
            <div>
                <p>hi?</p>
                {this.state}
            </div>
        );
    }
}

export default Mainpage;

Before that, I wrote on react about a year ago, and then a similar design worked

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I see you’re using React Router v6. Route should be written as such:

<Route path="/" element={<Mainpage/>}/>

This should fix your issue. Else, please provide more code and your complete error.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading