React router this.props.children rendering issu

use the render method of react-router-dom "s route tag, which cannot be rendered using this.props.children in the component

related environment react16

related codes

index.js

import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";

ReactDOM.render(<App />, document.getElementById("root"));

app.js

import React, { Component } from "react";
import MyLayout from "./components/Layout/Layout";
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import "antd/dist/antd.css";

import Login from "./page/Login/Login";
import Home from "./page/Home/Home";
import ArticleList from "./page/ArticleList/ArticleList";
import NewArticle from "./page/NewArticle/NewArticle";


class App extends Component {
  render() {
    let LayoutRouter = (
      <MyLayout>
        <Switch>
          <Route exact path="/" Component={Home} />
          <Route path="/article/list" Component={ArticleList} />
          <Route path="/article/new" Component={NewArticle} />
        </Switch>
      </MyLayout>
    );
    return (
      <Router>
        <Switch>
          <Route path="/login" Component={Login} />
          <Route path="/" render={ props => LayoutRouter } />
        </Switch>
      </Router>
    )
  }
};

export default App;

MyLayout components

import React, { Component } from "react";
import { Layout } from "antd";
import SideNav from "../SideNav/SideNav";
import TopNav from "../TopNav/TopNav";

const { Content } = Layout;

class MyLayout extends Component {
  render() {
    console.log(this.props.children);
    return (
      <Layout className="myLayout">
        <SideNav />
        <Layout>
          <TopNav />
          <Content style={{margin: "0 16px"}} >
            
            {this.props.children}
          </Content>
        </Layout>
      </Layout>
    )
  }
}

export default MyLayout;

Home.js

import React, { Component } from "react";

class Home extends Component {
  render() {
    return <div></div>
  }
}

export default Home;

results after running

clipboard.png

clipboard.png

in which the word "content" is rendered, but this.props.children does not render it, nor does it report an error


component on your Route should be lowercase, right?
nested routing also uses the component, code as follows:

<Router>
    <Switch>
      <Route exact path="/" component={LayoutRouter} />
    </Switch>
</Router>
const LayoutRouter = (props) => {
      return (
        <MyLayout>
          <Router history={props.history}>
            <Switch>
              <Route path="/" component={Home} />
            </Switch>
          </Router>
        </MyLayout>
      )
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea6afa-1df9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea6afa-1df9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?