<Router initialEntries={['/home']}>
<Switch>
<Route exact path='/home' component={Home} />
<Route exact path='/todo' component={Todo} />
<Route exact path='/message' component={Message} />
<Route exact path='/me' component={PersonalCenter} />
</Switch>
</Router>
出现这样的错误:
Attempted import error: 'Switch' is not exported from 'react-router-dom'.
原因是在 react-router-dom 6.0以后 Switch 就不用了
在package.json 中看了一下版本:
修改成为:
<Router initialEntries={['/home']}>
<Routes>
<Route exact path='/home' component={Home} />
<Route exact path='/todo' component={Todo} />
<Route exact path='/message' component={Message} />
<Route exact path='/me' component={PersonalCenter} />
</Routes>
</Router>
Switch 修改为 Routes
无报错
希望对你有所帮助