-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
92 lines (81 loc) · 2.21 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React from 'react';
import Link from 'next/link';
import Title from '../components/title';
import Router from 'next/router';
const Home = () => {
const goToPage5 = () => {
Router.push({
pathname: '/page5',
query: {
name: 'John'
}
});
};
const goToPage6 = ()=>{
Router.push({pathname:"/page6",query:{name:"Amy"}});
}
Router.events.on('routeChangeStart', (...args) => {
console.log(`1.routeChangeStart路由发生变化的时候,参数为:${args}`);
});
Router.events.on('routeChangeComplete', (...args) => {
console.log(`2.routeChangeComplete路由结束变化的时候,参数为:${args}`);
});
Router.events.on('beforeHistoryChange', (...args) => {
console.log(`3.beforeHistoryChange浏览器History出发之前,参数为:${args}`);
});
Router.events.on('routeChangeError', (...args) => {
console.log(`4.routeCHangeError路由器跳转错误的时候,参数为:${args}`);
});
Router.events.on('hashChangeStart', (...args) => {
console.log(`5.hashChangeStart跳转开始时触发,参数为:${args}`);
});
Router.events.on('hashChangeComplete', (...args) => {
console.log(`6.hashChangeComplete跳转完成时触发,参数为:${args}`);
});
return (
<div>
<Title>ProbeDream</Title>
<div>
<Link href="/page1">
<a>go to page1!</a>
</Link>
</div>
<div>
<Link href="/page2">
<a>go to page2!</a>
</Link>
</div>
<button
onClick={() => {
Router.push('/page1');
}}
>
goA
</button>
<button
onClick={() => {
Router.push('/page2');
}}
>
goB
</button>
<br />
<Link href="/page3?name=小p">
<a>他是小p</a>
</Link>
<br />
<Link href={{ pathname: '/page5', query: { name: 'Julia' } }}>
<a>Hello Julia!</a>
</Link>
<br />
<Link href="/page5?name=Joe">
<a>Hello Joe!</a>
</Link>
<br/>
<button onClick={goToPage5}>goToPage5</button>
<br/>
<button onClick={()=>{Router.push({pathname:"/page6",query:{name:"Amy"}})}}>goToPage6</button>
</div>
);
};
export default Home;