• React的路由跳转


    要实现React的路由跳转,需要用react-router-dom组件。

    "react-router-dom": "^6.2.1"

    在App.js配置路由

    import React, { Component } from 'react';
    import './App.scss';  // 引入样式文件
    import { HashRouter, Route, Routes, Navigate } from "react-router-dom";
    import Home from './view/Home.jsx';
    import Config from './view/Config.jsx';
    import Draw from './view/Draw.jsx';
    
    class App extends Component {
      constructor(props) {
        super(props);
        this.state = {};
      }
    
      render() {
        return (
          <HashRouter>
            <main>
                <Routes>
                  <Route path="/home" exact element={<Home />}/>
                  <Route path="/config" exact element={<Config />}/>
                  <Route path="/draw" exact element={<Draw />}/>
                  <Route path="*" element={<Navigate to="/home" />} />
                </Routes>
            </main>
          </HashRouter>
        );
      }
    }
    export default App;

    新建Home.jsx,进行路由跳转

    import React, { Component } from 'react';
    import { Button } from 'antd'
    import { Link } from "react-router-dom";
    
    class Home extends Component {
      constructor(props) {
        super(props);
        this.state = {};
      }
    
      jumpToConfigPage(){
    
      }
    
      render() {
        return (
          <div>
            <h1>红包幸运抽奖系统</h1>
            <center className="btns">
              <Link to="/config">
                <Button type="primary" shape="round">配置</Button>
              </Link>
              <Link to="/draw">
                <Button type="primary" shape="round">抽奖</Button>
              </Link>
            </center>
          </div>
        );
      }
    }
    export default Home;

    新建Draw.jsx

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

    新建Config.jsx

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

    即可。

  • 相关阅读:
    Jmeter_远程启动 I
    jmeter(九)逻辑控制器
    Mysql innodb 间隙锁 (转)
    MySQL- InnoDB锁机制
    Innodb间隙锁,细节讲解(转)
    性能测试:压测中TPS上不去的几种原因分析(就是思路要说清楚)
    Redis性能调优
    Redis基础
    VMThread占CPU高基本上是JVM在频繁GC导致,原因基本上是冰法下短时间内创建了大量对象堆积造成频繁GC。
    关于Hibernate二级缓存第三方插件EHCache缓存
  • 原文地址:https://www.cnblogs.com/luoyihao/p/15800045.html
Copyright © 2020-2023  润新知