<Route exact path="/" component={Main}></Route>
<Route path="/about" component={About}></Route>
<Route path="/topic" component={Topic}></Route>
1.1: 外面无switch不加exact
1.2: 外面无switch加exact
<Switch>
<Route exact path="/" component={Main}></Route>
<Route path="/about" component={About}></Route>
<Route path="/topic" component={Topic}></Route>
</Switch>
2.1:外面包裹switch以后加exact
2.2:外面包裹switch以后不加exact
import React from 'react';
import {HashRouter as Router,Link,Route,Switch} from 'react-router-dom';
import Home from "./../route1/Home.js";
import Main from "./../route1/Main.js";
import About from "./../route1/About.js";
import Topic from "./../route1/Topic.js";
export default class IRouter extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<Router>
<Home>
<Route exact path="/" component={Main}></Route>
<Route path="/about" component={About}></Route>
<Route path="/topic" component={Topic}></Route>
</Home>
</Router>
</div>
);
}
}