1、安装:yarn add [email protected]
2、引入:import { HashRouter as Router, Route } from ‘react-router-dom’;
import React from 'react';
import ReactDOM from 'react-dom';
import {HashRouter as Router, Route, Link} from 'react-router-dom';
import 'font-awesome/css/font-awesome.min.css';
import './index.css';
import './index.scss';
class A extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
Component A
</div>
)
}
}
class B extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>Component B</div>
)
}
}
class Wrapper extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<p><Link to="/a">组件A</Link></p>
<p><Link to="/b">组件B</Link></p>
{this.props.children}
</div>
)
}
}
ReactDOM.render(
<Router>
<Wrapper>
<Route path="/a" component={A}></Route>
<Route path="/b" component={B}></Route>
</Wrapper>
</Router>,
document.getElementById('app')
);
组件A的路径:http://localhost:8086/dist/#/a
组件B的路径:http://localhost:8086/dist/#/b