File tree 4 files changed +56
-6
lines changed
4 files changed +56
-6
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ export default VueRouter
5
5
6
6
export {
7
7
RouterMode ,
8
+ RouteMeta ,
8
9
RawLocation ,
9
10
RedirectOption ,
10
11
RouterOptions ,
Original file line number Diff line number Diff line change @@ -126,7 +126,7 @@ interface _RouteConfigBase {
126
126
children ?: RouteConfig [ ]
127
127
redirect ?: RedirectOption
128
128
alias ?: string | string [ ]
129
- meta ?: any
129
+ meta ?: RouteMeta
130
130
beforeEnter ?: NavigationGuard
131
131
caseSensitive ?: boolean
132
132
pathToRegexpOptions ?: PathToRegexpOptions
@@ -153,7 +153,7 @@ export interface RouteRecord {
153
153
parent ?: RouteRecord
154
154
redirect ?: RedirectOption
155
155
matchAs ?: string
156
- meta : any
156
+ meta : RouteMeta
157
157
beforeEnter ?: (
158
158
route : Route ,
159
159
redirect : ( location : RawLocation ) => void ,
@@ -205,5 +205,7 @@ export interface Route {
205
205
fullPath : string
206
206
matched : RouteRecord [ ]
207
207
redirectedFrom ?: string
208
- meta ?: any
208
+ meta ?: RouteMeta
209
209
}
210
+
211
+ export interface RouteMeta extends Record < string | number | symbol , any > { }
Original file line number Diff line number Diff line change @@ -18,7 +18,9 @@ const Abc = { template: '<div>abc</div>' }
18
18
const Async = ( ) => Promise . resolve ( { template : '<div>async</div>' } )
19
19
20
20
let err : any
21
- if ( VueRouter . isNavigationFailure ( err , VueRouter . NavigationFailureType . aborted ) ) {
21
+ if (
22
+ VueRouter . isNavigationFailure ( err , VueRouter . NavigationFailureType . aborted )
23
+ ) {
22
24
err . from . fullPath . split ( '/' )
23
25
}
24
26
@@ -104,7 +106,7 @@ const router = new VueRouter({
104
106
abc : Abc ,
105
107
asyncComponent : Async
106
108
} ,
107
- meta : { auth : true } ,
109
+ meta : { auth : true , nested : { foo : '' } } ,
108
110
beforeEnter ( to , from , next ) {
109
111
to . params
110
112
from . params
@@ -229,7 +231,7 @@ const Components: (
229
231
| AsyncComponent
230
232
) [ ] = router . getMatchedComponents ( )
231
233
232
- const match : Route = router . match ( '/more' ) ;
234
+ const match : Route = router . match ( '/more' )
233
235
234
236
const vm = new Vue ( {
235
237
router,
Original file line number Diff line number Diff line change
1
+ import VueRouter from '../index'
2
+
3
+ const component = { template : '<div>home</div>' }
4
+
5
+ declare module '../index' {
6
+ export interface RouteMeta {
7
+ requiresAuth ?: boolean
8
+ nested : { foo : string }
9
+ }
10
+ }
11
+
12
+ const router = new VueRouter ( {
13
+ routes : [
14
+ {
15
+ path : '/' ,
16
+ component,
17
+ meta : {
18
+ requiresAuth : true ,
19
+ // still allowed
20
+ other : true ,
21
+ nested : {
22
+ foo : 'bar'
23
+ }
24
+ }
25
+ } ,
26
+ {
27
+ path : '/foo' ,
28
+ component,
29
+ // @ts -expect-error
30
+ meta : { }
31
+ }
32
+ ]
33
+ } )
34
+
35
+ router . beforeEach ( to => {
36
+ // should pass
37
+ if ( to . meta ! . requiresAuth === true ) {
38
+ }
39
+ // still pass because any
40
+ if ( to . meta ! . lol === true ) {
41
+ }
42
+ // @ts -expect-error: nested will never be true
43
+ if ( to . meta ! . nested === true ) {
44
+ }
45
+ } )
You can’t perform that action at this time.
0 commit comments