• react路由的简单例子2


    这个和我上一篇文章是差不多的,只不过这里的组件都不是无状态组件

    Test.js

    import React, { Component } from "react";
    import { BrowserRouter as Router, Route, Link } from "react-router-dom";
    import Index from '../pages/Index'
    import List from './List'
    class Test extends Component {
      constructor(props) {
        super(props);
        this.state = {};
      }
      render() {
        return (
          <div>
            <Router>
              <ul>
                <li>
                    <Link to="/">首页</Link>
                </li>
                <li>
                    <Link to="/list/">列表</Link>
                </li>
                <Route path="/" exact component={Index}></Route>
                <Route path="/list/" exact component={List}></Route>
              </ul>
            </Router>
          </div>
        );
      }
    }
    
    export default Test;

    Index.js

    import React, { Component } from 'react';
    class Index extends Component {
        constructor(props) {
            super(props);
            this.state = {  }
        }
        render() { 
            return ( 
                <div>
                    index
                </div>
             );
        }
    }
     
    export default Index;

    List.js

    import React, { Component } from 'react';
    class List extends Component {
        constructor(props) {
            super(props);
            this.state = {  }
        }
        render() { 
            return ( 
                <div>
                    list
                </div>
             );
        }
    }
     
    export default List;
  • 相关阅读:
    23.Java函数
    22.java中的break和continue关键字
    21.Java中for循环
    20.java中的while循环
    19.java中选择判断语句(switch)
    18.java中判断(if…else)
    17.java运算符的优先级与结合性
    16.Java三元运算符
    数组去重
    数组 字符串 对象 常用方法
  • 原文地址:https://www.cnblogs.com/luguankun/p/13975555.html
Copyright © 2020-2023  润新知