Error: Invariant failed: You should not use <withRouter(RouterView) /> outside a <Router>
问题代码:
import React, {Component} from 'react';
import {BrowserRouter as Router, Route, Switch, withRouter} from 'react-router-dom';
import * as A from '../a';
import * as B from '../b';
class RouterView extends Component{
render() {
return (
<Router>
<Switch>
<Route path="/" component={A}/>
<Route path="/b" component={B}/>
</Switch>
</Router>
);
}
}
export default withRouter(RouterView)
解决:将BrowserRouter
摘出来即可
over。。。