Skip to content

Commit c7eb193

Browse files
committed
refactor: 使用hooks重构404组件
1 parent 9d8f2a2 commit c7eb193

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

src/views/error/404/index.jsx

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
1-
import React, { Component } from "react";
1+
import React from "react";
22
import { Button, Row, Col } from "antd";
3-
import { connect } from "react-redux";
4-
import errImg from '@/assets/images/404.png'
3+
import errImg from "@/assets/images/404.png";
54
import "./index.less";
65

7-
/*
8-
前台404页面
9-
*/
10-
class NotFound extends Component {
11-
goHome = () => {
12-
this.props.history.replace("/");
13-
};
6+
const NotFound = (props) => {
7+
const { history } = props;
8+
const goHome = () => history.replace("/");
9+
return (
10+
<Row className="not-found">
11+
<Col span={12}>
12+
<img src={errImg} alt="404" />
13+
</Col>
14+
<Col span={12} className="right">
15+
<h1>404</h1>
16+
<h2>抱歉,你访问的页面不存在</h2>
17+
<div>
18+
<Button type="primary" onClick={goHome}>
19+
回到首页
20+
</Button>
21+
</div>
22+
</Col>
23+
</Row>
24+
);
25+
};
1426

15-
render() {
16-
return (
17-
<Row className="not-found">
18-
<Col span={12}>
19-
<img src={errImg} alt="404"/>
20-
</Col>
21-
<Col span={12} className="right">
22-
<h1>404</h1>
23-
<h2>抱歉,你访问的页面不存在</h2>
24-
<div>
25-
<Button type="primary" onClick={this.goHome}>
26-
回到首页
27-
</Button>
28-
</div>
29-
</Col>
30-
</Row>
31-
);
32-
}
33-
}
34-
35-
export default connect()(NotFound);
27+
export default NotFound;

0 commit comments

Comments
 (0)