zoukankan      html  css  js  c++  java
  • react-router

    1 SPA

     

    1.1 Single Page Application

    1.2 页面不刷新

    2 创建项目(参考 react.org)

    3 简单的例子

     

    3.1 index.js 入口配置

    import React from 'react';
    import ReactDOM from 'react-dom';
    import './index.css';
    import App from './App';
    import * as serviceWorker from './serviceWorker';
    
    //为了和其他的路由名称使用一致,重命名路由名 称
    import {BrowserRouter as Router} from 'react-router-dom';
    
    ReactDOM.render(
        <Router>
            <App/>
        </Router>,
        document.getElementById('root'));
    
    // If you want your app to work offline and load faster, you can change
    // unregister() to register() below. Note this comes with some pitfalls.
    // Learn more about service workers: https://bit.ly/CRA-PWA
    serviceWorker.unregister();
    

    3.2 App.js

    必要的一些组件自行创建

    import React from 'react';
    
    import {Link, Route} from 'react-router-dom';
    
    import C1 from './components/C1';
    import C2 from './components/C2';
    import C3 from './components/C3';
    
    // 路由规则是匹配前缀
    // 添加 exact 要求精确匹配
    function App() {
        return (
            <div>
                <Link to='/'>p1</Link>
                <Link to={'/p2'}>p2</Link>
                <Link to={'/p3'}>p3</Link>
    
                <Route path='/' exact component={C1}/>
                <Route path={'/p2'} component={C2}/>
                <Route path={'/p3'} component={C3}/>
            </div>
        )
    }
    
    export default App;
    

    Created: 2019-11-30 周六 17:39

    Validate

  • 相关阅读:
    分布式事务系列--分布式跨库查询解决方案 mysql federated引擎的使用
    【MySQL】跨库join
    实操手册:如何玩转跨库Join?跨数据库实例查询应用实践
    实现数据库的跨库join
    微服务改造中解决跨库问题的思路
    从jar包中加载feignClient
    注入jar包里的对象,用@autowired使用
    使用 IntraWeb (27)
    使用 IntraWeb (26)
    使用 IntraWeb (25)
  • 原文地址:https://www.cnblogs.com/heidekeyi/p/11963370.html
Copyright © 2011-2022 走看看