Your Name 3 年之前
父節點
當前提交
ee130a953d
共有 4 個檔案被更改,包括 45 行新增4 行删除
  1. 2
    2
      config/proxy.js
  2. 39
    0
      src/components/RouterEvent/index.jsx
  3. 0
    1
      src/layouts/BasicLayout.jsx
  4. 4
    1
      src/layouts/BlankLayout.jsx

+ 2
- 2
config/proxy.js 查看文件

@@ -8,8 +8,8 @@
8 8
 export default {
9 9
   dev: {
10 10
     '/api/': {
11
-      // target: 'https://xlk.njyz.tech/',
12
-      target: 'http://localhost:8081/',
11
+      target: 'https://xlk.njyz.tech/',
12
+      // target: 'http://localhost:8081/',
13 13
       // target: 'https://www.newhousehold.cn',
14 14
       changeOrigin: true,
15 15
       pathRewrite: {

+ 39
- 0
src/components/RouterEvent/index.jsx 查看文件

@@ -0,0 +1,39 @@
1
+import { Component, Fragment } from "react";
2
+import withRouter from 'umi/withRouter';
3
+import Prompt from 'umi/prompt';
4
+
5
+class RouterEvent extends Component {
6
+  state = {
7
+    location: {}
8
+  }
9
+
10
+  componentDidMount() {
11
+    console.log('-----props------->', this.props)
12
+
13
+    this.props.onEnter();
14
+    this.setState({ location: this.props.location });
15
+  }
16
+
17
+  componentDidUpdate() {
18
+    const originURL = this.props.location.pathname + this.props.location.search
19
+    const currentURL = this.state.location.pathname + this.state.location.search
20
+
21
+    if (originURL != currentURL) {
22
+      this.props.onEnter();
23
+      this.setState({ location: this.props.location });
24
+    }
25
+  }
26
+
27
+  render() {
28
+    const onLeave = this.props.onLeave;
29
+
30
+    return (
31
+      <div>
32
+        <Prompt message={() => { onLeave(); return true; }} />
33
+        {this.props.children}
34
+      </div>
35
+    );
36
+  }
37
+}
38
+
39
+export default withRouter(RouterEvent)

+ 0
- 1
src/layouts/BasicLayout.jsx 查看文件

@@ -76,7 +76,6 @@ const BasicLayout = (props) => {
76 76
       authority: authority && authority.length ? authority : ['any-string-for-no-right'],
77 77
     };
78 78
   })
79
-  
80 79
 
81 80
   return (
82 81
     <ProLayout

+ 4
- 1
src/layouts/BlankLayout.jsx 查看文件

@@ -1,8 +1,11 @@
1 1
 import React from 'react';
2
+import RouterEvent from '@/components/RouterEvent';
2 3
 
3 4
 const Layout = ({ children }) => {
4 5
   return (
5
-    <>{children}</>
6
+    <RouterEvent onEnter={() => console.log('------onEnter--------')} onLeave={() => console.log('------onLeave--------')}>
7
+      <>{children}</>
8
+    </RouterEvent>
6 9
   );
7 10
 };
8 11