Skip to content

Commit 1b9bf1a

Browse files
committed
refactor: 将顶部进度条的实现放在Loading组件中
1 parent 5e8a1a8 commit 1b9bf1a

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/components/Loading/index.jsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
import React from "react";
1+
import React, { Component } from "react";
22
import { Spin } from "antd";
3+
import NProgress from "nprogress"; // progress bar
4+
import "nprogress/nprogress.css"; // progress bar style
35

4-
const Loading = () => {
5-
return (
6-
<div className="app-container">
7-
<Spin />
8-
</div>
9-
);
10-
};
6+
NProgress.configure({ showSpinner: false }); // NProgress Configuration
7+
8+
class Loading extends Component {
9+
componentDidMount() {
10+
NProgress.start();
11+
}
12+
componentWillUnmount() {
13+
NProgress.done();
14+
}
15+
render() {
16+
return (
17+
<div className="app-container">
18+
<Spin />
19+
</div>
20+
);
21+
}
22+
}
1123

1224
export default Loading;

src/views/layout/Content/index.jsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ import { Redirect, withRouter, Route, Switch } from "react-router-dom";
33
import DocumentTitle from "react-document-title";
44
import { connect } from "react-redux";
55
import { CSSTransition, TransitionGroup } from "react-transition-group";
6-
import NProgress from "nprogress"; // progress bar
7-
import "nprogress/nprogress.css"; // progress bar style
8-
96
import { Layout } from "antd";
107
import { getMenuItemInMenuListByProperty } from "@/utils";
118
import routeList from "@/config/routeMap";
129
import menuList from "@/config/menuConfig";
1310
const { Content } = Layout;
14-
NProgress.configure({ showSpinner: false }); // NProgress Configuration
1511

1612
const getPageTitle = (menuList, pathname) => {
1713
let title = "Ant Design Pro";
@@ -38,8 +34,6 @@ const LayoutContent = (props) => {
3834
timeout={500}
3935
classNames="fade"
4036
exit={false}
41-
onEnter={() => NProgress.start()}
42-
onEntered={() => NProgress.done()}
4337
>
4438
<Switch location={location}>
4539
<Redirect exact from="/" to="/dashboard" />

0 commit comments

Comments
 (0)