|
@@ -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)
|