美文网首页
一个简单路由的搭建

一个简单路由的搭建

作者: 馋中解禅 | 来源:发表于2017-08-21 12:59 被阅读0次

    1.安装插件

    npm install react-router-dom --save-dev
    

    2.新建路由

    //routes.js
    import React from 'react'
    import {
        BrowserRouter as Router,
        Route,
    } from 'react-router-dom'
    import App from './App'
    import App2 from './App2'
    import App3 from './App3'
    
    const Routers = () => (
        <Router>
            <div>
                <Route exact path="/" component={App}/>
                <Route path="/app" component={App}/>
                <Route path="/app2" component={App2}/>
                <Route path="/app3" component={App3}/>
            </div>
        </Router>
    )
    export default Routers
    

    3.路由跳转

    //顶部添加
    import {Link} from 'react-router-dom' 
    //跳转实现
    <Link to="/app2">app2</Link>
    <Link to="/app2">app3</Link>
    

    相关文章

      网友评论

          本文标题:一个简单路由的搭建

          本文链接:https://www.haomeiwen.com/subject/wwytdxtx.html