剧场模式
首页前端React轻松学 React-Router 4

轻松学 React-Router 4 #03 Link

海外散仙厉飞雨 · 真仙发布于
2

src/App.js

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import About from './About';
import Home from './Home';

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

// import Link from 'react-router-dom/Link';

class App extends Component {
  render() {
    return (
      <Router>
        <div className="App">
          <header className="App-header">
            <img src={logo} className="App-logo" alt="logo" />
            <h1 className="App-title">Welcome to React</h1>
          </header>
          <div className="App-intro">
            <ul>
              <li><Link to="/">Home</Link></li>
              <li><Link to="/about">About</Link></li>
              <li><Link to="/error">Error</Link></li>
            </ul>
            <Route path="/" component={ Home } />
            <Route path="/about" component={ About } />
            <Route path="/home" component={ Home } />
          </div>
        </div>
      </Router>
    );
  }
}

export default App;
0 条回复
暂无回复~~

© 汕尾市求知科技有限公司 | 粤ICP备19038915号 | 在线学员:42

Top