【发布时间】:2018-11-08 03:01:17
【问题描述】:
我有一个问题不知道如何解决,运行 npm test 时出现此错误
不变违规:您不应在
<Router>之外使用<Switch>
问题可能是什么,我该如何解决?我跑的测试是react自带的标准app.test.js
class App extends Component {
render() {
return (
<div className = 'app'>
<nav>
<ul>
<li><Link exact activeClassName="current" to='/'>Home</Link></li>
<li><Link exact activeClassName="current" to='/TicTacToe'>TicTacToe</Link></li>
<li><Link exact activeClassName="current" to='/NumGame'>Quick Maths</Link></li>
<li><Link exact activeClassName="current" to='/HighScore'>Highscore</Link></li>
<li><Link exact activeClassName="current" to='/Profile'>Profile</Link></li>
<li><Link exact activeClassName="current" to='/Login'>Sign out</Link></li>
</ul>
</nav>
<Switch>
<Route exact path='/' component={Home}></Route>
<Route path='/TicTacToe' component={TicTacToe}></Route>
<Route path='/NumGame' component={NumberGame}></Route>
<Route path='/HighScore' component={HighScore}></Route>
<Route path='/Profile' component={Profile}></Route>
<Route path='/Login' component={SignOut1}></Route>
</Switch>
</div>
);
}
};
【问题讨论】:
-
请注意,此错误与您正在运行单元测试这一事实没有任何关系 - 您也会在运行时得到它。
标签: javascript reactjs react-router