当前位置 : 主页 > 网页制作 > React >

react --- 路由

来源:互联网 收集:自由互联 发布时间:2021-06-15
1. 安装 npm install --save react-router-dom 2. 引入 import { BrowserRouter as Router, Route, Link } from "react-router-dom"; 3. 引入模块 import Home from ‘./page/Home.js‘; 4. 实现代码 Router div ul li Link to="/"Home/Link /l

1.  安装

   npm install --save react-router-dom

 

2.  引入

   import { BrowserRouter as Router, Route, Link } from "react-router-dom";

 

3.  引入模块

   import Home from ‘./page/Home.js‘;

 

4.  实现代码

    

<Router>
      <div>
        <ul>
          <li>
            <Link to="/">Home</Link>
          </li>
          <li>
            <Link to="/about">About</Link>
          </li>
          <li>
            <Link to="/topics">Topics</Link>
          </li>
        </ul>

        <hr />

        <Route exact path="/" component={Home} />
        <Route path="/about" component={About} />
        <Route path="/topics" component={Topics} />
      </div>
    </Router>
网友评论