1. 默认路由在V5被废除
-
Attempted import error: 'IndexRoute' is not exported from 'react-router-dom'.
ps:在react-router
V5 已经废除掉了默认路由
如图,在react-router
的官方文档里面已经找不到IndexRoute
的API的。 -
tiny-warning.esm.js:11 Warning: You should not use <Route component> and <Route children> in the same route; <Route component> will be ignored
- ⚠警告的路由组件写法
- 问题分析
开始的时候,想要使用默认路由,后来发现被废弃了,直接从
IndexRoute
改成了Route
,忘记调整顺序。
- 解决办法
import {
Route, Switch } from 'react-router';
import App from '../views/App/App'
import Login from '../views/Login/Login'
import {
BrowserRouter } from 'react-router-dom';
function Routes() {
return (
<BrowserRouter >
<Switch>
<Route path='/' component={
App} />
<Route path='/Login' component={
Login} />
</Switch>
</BrowserRouter>
);
}
export default Routes;
2、组件问题
Warning: The tag <routes> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter. at routes
组件的首字母应该不写,不然识别不了
Warning: Login(...): No
rendermethod found on the returned component instance: you may have forgotten to define
render.
- 报错代码
import React from 'react';
import {
withRouter } from 'react-router';
class Login extends React.Component{
render(){
return (
<div className="login">
登录
</div>
)
}
}
export default withRouter(Login)
3. 构造器问题
src\views\Login\Login.jsx Line 5:5: Useless constructor no-useless-constructor
- 解决办法:加
return
- 不要使用没有调用的
constructor
- 错误代码,还是上面的登录代码(听者伤心闻者流泪)
- 解决办法: 把
constructor
注释掉
- 结果
tiny-warning.esm.js:11 Warning: You should not use <Route component> and <Route children> in the same route; <Route component> will be ignored
感言
转载:https://blog.csdn.net/qq_45704048/article/details/117368996
查看评论