-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
types: add RouteMeta interface to enable module augmentation (#3385)
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
- Loading branch information
1 parent
306602d
commit 260f737
Showing
4 changed files
with
56 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ export default VueRouter | |
|
||
export { | ||
RouterMode, | ||
RouteMeta, | ||
RawLocation, | ||
RedirectOption, | ||
RouterOptions, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import VueRouter from '../index' | ||
|
||
const component = { template: '<div>home</div>' } | ||
|
||
declare module '../index' { | ||
export interface RouteMeta { | ||
requiresAuth?: boolean | ||
nested: { foo: string } | ||
} | ||
} | ||
|
||
const router = new VueRouter({ | ||
routes: [ | ||
{ | ||
path: '/', | ||
component, | ||
meta: { | ||
requiresAuth: true, | ||
// still allowed | ||
other: true, | ||
nested: { | ||
foo: 'bar' | ||
} | ||
} | ||
}, | ||
{ | ||
path: '/foo', | ||
component, | ||
// @ts-expect-error | ||
meta: {} | ||
} | ||
] | ||
}) | ||
|
||
router.beforeEach(to => { | ||
// should pass | ||
if (to.meta!.requiresAuth === true) { | ||
} | ||
// still pass because any | ||
if (to.meta!.lol === true) { | ||
} | ||
// @ts-expect-error: nested will never be true | ||
if (to.meta!.nested === true) { | ||
} | ||
}) |