1
- import { createRouter , createWebHistory , useRoute } from '../../src'
1
+ import { createRouter , createWebHistory } from '../../src'
2
2
import { RouteComponent } from '../../src/types'
3
- import { createApp } from 'vue'
3
+ import { createApp , defineComponent } from 'vue'
4
4
5
5
const component : RouteComponent = {
6
6
template : `<div>A component</div>` ,
@@ -10,58 +10,68 @@ const Home: RouteComponent = {
10
10
template : `<div>Home</div>` ,
11
11
}
12
12
13
- const Document : RouteComponent = {
14
- template : `<div>Document: {{ route.params.id }}</div>` ,
15
- setup ( ) {
16
- return { route : useRoute ( ) }
17
- } ,
18
- }
13
+ const ParamId = defineComponent ( {
14
+ template : `<div>id: <span id="p-id">"{{ $route.params.id }}"</span></div>` ,
15
+ } )
16
+
17
+ // full URL / !"$&'()*+,:;<=>%3F@[]^`{|}?a= !"$&'()*+,/:;<=>?@[]^`{|}# !"#$&'()*+,:;<=>?@[]^`{|}
19
18
20
19
const router = createRouter ( {
20
+ // TODO: allow hash based history
21
21
history : createWebHistory ( '/' + __dirname ) ,
22
22
routes : [
23
23
{ path : '/' , component : Home , name : 'home' } ,
24
- { path : '/documents/:id' , name : 'docs' , component : Document } ,
24
+ { path : '/:id' , component : ParamId , name : 'param' } ,
25
+ { path : '/documents/:id' , name : 'docs' , component : ParamId } ,
25
26
{ path : encodeURI ( '/n/€' ) , name : 'euro' , component } ,
26
27
] ,
27
28
} )
28
29
29
30
const app = createApp ( {
30
31
setup ( ) {
31
- const route = useRoute ( )
32
- return { route }
32
+ const url =
33
+ '/' +
34
+ __dirname +
35
+ '/ !"%23$&\'()*+,%2F:;<=>%3F@[]^`{|}?a= !"$%26\'()*+,/:;<=>?@[]^`{|}# !"#$&\'()*+,/:;<=>?@[]^`{|}'
36
+ const urlObject = {
37
+ name : 'param' ,
38
+ params : { id : ' !"#$&\'()*+,/:;<=>?@[]^`{|}' } ,
39
+ query : { 'a=' : ' !"#$&\'()*+,/:;<=>?@[]^`{|}' } ,
40
+ hash : '# !"#$&\'()*+,/:;<=>?@[]^`{|}' ,
41
+ }
42
+ return { url, urlObject }
33
43
} ,
34
44
35
45
template : `
36
46
<div id="app">
37
47
<section class="info">
38
48
Name:
39
- <pre id="name">{{ route.name }}</pre>
49
+ <pre id="name">{{ $ route.name }}</pre>
40
50
</section>
41
51
42
52
<section class="info">
43
53
Params:
44
- <pre id="params">{{ route.params }}</pre>
54
+ <pre id="params">{{ $ route.params }}</pre>
45
55
</section>
46
56
47
57
<section class="info">
48
58
Query:
49
- <pre id="query">{{ route.query }}</pre>
59
+ <pre id="query">{{ $ route.query }}</pre>
50
60
</section>
51
61
52
62
<section class="info">
53
63
Hash:
54
- <pre id="hash">{{ route.hash }}</pre>
64
+ <pre id="hash">{{ $ route.hash }}</pre>
55
65
</section>
56
66
57
67
<section class="info">
58
68
FullPath:
59
- <pre id="fullPath">{{ route.fullPath }}</pre>
69
+ <pre id="fullPath">{{ $ route.fullPath }}</pre>
60
70
</section>
61
71
62
72
<section class="info">
63
73
path:
64
- <pre id="path">{{ route.path }}</pre>
74
+ <pre id="path">{{ $ route.path }}</pre>
65
75
</section>
66
76
67
77
<hr />
@@ -95,6 +105,15 @@ const app = createApp({
95
105
router)</a
96
106
>
97
107
</li>
108
+ <li>
109
+ <a :href="url"
110
+ >Unencoded URL (force reload)</a
111
+ >
112
+ </li>
113
+ <li>
114
+ <router-link :to="urlObject"
115
+ >Encoded by router</router-link>
116
+ </li>
98
117
</ul>
99
118
100
119
<router-view></router-view>
0 commit comments