最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论