# React中子组件无法进行路由跳转的问题
- 子组件引入withRouter
import {withRouter} from "react-router-dom";
class Title extends Component {
outLogin = () => {
//跳转路由
this.props.history.push('/');
}
}
export default withRouter(Title);
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# Switch作用
- 为了解决route的唯一渲染,它是为了保证路由只渲染一个路径。
# exact作用
- 只有页面的路由和
<Route>的path属性精确比对后完全相同该<Route>才会被渲染。