-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathreplace-stay-example.html
82 lines (75 loc) · 2.35 KB
/
replace-stay-example.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- <script src="../debug/vue.js"></script>
<script src="../debug/vue-router.js"></script> -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/[email protected]/dist/vue-router.js"></script>
<script src="../dist/index.js"></script>
</head>
<body>
<div id="app">
<h1>Hello App!</h1>
<keep-alive>
<router-view></router-view>
</keep-alive>
</div>
<script>
const Foo = {
name: 'foo',
template: '<div><p>this is foo page</p><router-link to="/bar">Go to Bar</router-link><div @click="replace">replaceToBar</div></div>',
beforeCreate() {
console.log("foo beforeCreate")
},
destroyed() {
console.log("foo destroyed")
},
methods:{
replace(){
this.$router.replace('/bar')
}
}
}
const Bar = {
name: 'bar',
template: '<div><p>this is bar page</p><router-link to="/baz">Go to Baz</router-link><div @click="replace">replaceToFoo</div></div>' ,
destroyed() {
console.log("bar destroyed")
},
methods:{
replace(){
this.$router.replace('/foo')
}
}
}
const Baz = {
name: 'baz',
template: '<div><p>this is baz page</p><div @click="goback">goBack</div><router-link to="/foo">Go to Foo</router-link></div>',
methods:{
goback(){
this.$router.back();
}
},
destroyed() {
console.log("baz destroyed")
},
}
const routes = [
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar },
{ path: '/baz', component: Baz }
]
const router = new VueRouter({
routes,
mode:'hash',
})
createHelper({Vue,router,replaceStay:['/foo']})
const app = new Vue({
router
}).$mount('#app')
</script>
</body>
</html>