reactjs - MERN Stack -TodoAPP - Nothing display when adding Route - Stack Overflow

Iam very new in that field and found this very interesting but got some issueHello everyoneI was le

I am very new in that field and found this very interesting but got some issue

Hello everyone

I was learning and practising tutorial on mern stack, by watching a video on youtube but nothing is displayed since I have added the Routes. White page. Is there anyone who get an idea what is wrong.

/

import { BrowserRouter as Router, Route, Link } from "react-router-dom";
import "bootstrap/dist/css/bootstrap.min.css";
import CreateTodo from "./components/create-todoponent";
import EditTodo from "./components/edit-todoponent";
import TodosList from "./components/todos-listponent";
class App extends Component {
  render() {
    return (
      
      <Router>
        <div className="container">
             <h2>MERN-Stack Todo App</h2>
              <Route path="/" exact element={TodosList} />
              <Route path="/edit/:id" element={EditTodo} />
              <Route path="/create" element={CreateTodo} />
            </div>
                  
        
      </Router>
      
    );
  }
}

export default App;   ``` 

Many thanks in advance

Regards

Fred

I am very new in that field and found this very interesting but got some issue

Hello everyone

I was learning and practising tutorial on mern stack, by watching a video on youtube but nothing is displayed since I have added the Routes. White page. Is there anyone who get an idea what is wrong.

https://www.codingthesmartway/the-mern-stack-tutorial-building-a-react-crud-application-from-start-to-finish-part-1/

import { BrowserRouter as Router, Route, Link } from "react-router-dom";
import "bootstrap/dist/css/bootstrap.min.css";
import CreateTodo from "./components/create-todoponent";
import EditTodo from "./components/edit-todoponent";
import TodosList from "./components/todos-listponent";
class App extends Component {
  render() {
    return (
      
      <Router>
        <div className="container">
             <h2>MERN-Stack Todo App</h2>
              <Route path="/" exact element={TodosList} />
              <Route path="/edit/:id" element={EditTodo} />
              <Route path="/create" element={CreateTodo} />
            </div>
                  
        
      </Router>
      
    );
  }
}

export default App;   ``` 

Many thanks in advance

Regards

Fred
Share Improve this question edited Mar 25 at 14:04 swiftboy asked Mar 25 at 13:59 swiftboyswiftboy 293 bronze badges 2
  • What version of react-router-dom is your application running on? – Hamed Jimoh Commented Mar 25 at 14:20
  • [email protected] – swiftboy Commented Mar 25 at 15:19
Add a comment  | 

1 Answer 1

Reset to default 1

It looks like the tutorial you're following is outdated and you're probably using a react-router-dom version that is higher than v5 but your code currently looks like it's still using some of the implementations for react-router-dom version 5. For example, the exact prop was removed from v6. Also, to solve the blank screen issue, you can wrap your routes around a Routes component.

import { BrowserRouter as Router, Route, Link, Routes } from "react-router-dom";

class App extends Component {
  render() {
    return (
      <Router>
        <div className="container">
          <h2>MERN-Stack Todo App</h2>
          <Routes>
            <Route path="/" element={<TodosList />} />
            <Route path="/edit/:id" element={<EditTodo />} />
            <Route path="/create" element={<CreateTodo/>} />
          </Routes>
        </div>
      </Router>
    );
  }
}

This should possibly fix your blank screen issue, but I'd advise you switch your learning resource from the current platform you're learning from as the contents are very outdated. If you need to learn and be up to date with React then the official docs is the way to go: https://react.dev/learn

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744191658a4562462.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信