Skip to content

Commit 5e8a1a8

Browse files
committed
feat: 路由跳转时添加顶部进度条
1 parent e2d232e commit 5e8a1a8

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

src/components/Loading/index.jsx

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

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-
}
4+
const Loading = () => {
5+
return (
6+
<div className="app-container">
7+
<Spin />
8+
</div>
9+
);
10+
};
2311

2412
export default Loading;

src/views/layout/Content/index.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ 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+
69
import { Layout } from "antd";
710
import { getMenuItemInMenuListByProperty } from "@/utils";
811
import routeList from "@/config/routeMap";
912
import menuList from "@/config/menuConfig";
1013
const { Content } = Layout;
14+
NProgress.configure({ showSpinner: false }); // NProgress Configuration
1115

1216
const getPageTitle = (menuList, pathname) => {
1317
let title = "Ant Design Pro";
@@ -29,7 +33,14 @@ const LayoutContent = (props) => {
2933
<DocumentTitle title={getPageTitle(menuList, pathname)}>
3034
<Content style={{ height: "calc(100% - 100px)" }}>
3135
<TransitionGroup>
32-
<CSSTransition key={location.pathname} timeout={500} classNames="fade" exit={false}>
36+
<CSSTransition
37+
key={location.pathname}
38+
timeout={500}
39+
classNames="fade"
40+
exit={false}
41+
onEnter={() => NProgress.start()}
42+
onEntered={() => NProgress.done()}
43+
>
3344
<Switch location={location}>
3445
<Redirect exact from="/" to="/dashboard" />
3546
{routeList.map((route) => {

0 commit comments

Comments
 (0)