Types for File-based Middleware / Navigation Guard #308
Replies: 1 comment 7 replies
-
maybe try extending |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello. I'm trying to replicate Nuxt's file-based middleware and the
definePageMeta({ middleware: [ 'auth' ] })
.I defined a Vite plugin that parses the files in
~/src/middleware
, to generate amiddleware-typed-router.d.ts
(which I added to
tsconfig.json
'sinclude
array of course)with the union of all the middleware names, so that I can have completion in
definePage({ meta: { middleware: [ 'auth' ] }})
I of course loop through the routes and read the middleware array (or string) and add a
router.beforeEach
that calls the handler of the modules.This all works. What I need a hand is in the types for
middleware-typed-router.d.ts
.I tried reimplementing the RouteMeta interface from vue-router/auto.
Tried using Parameters<> and ReturnType<> to extend definePage.
My middleware array ends as
string[]
instead of'auth'[] | undefined
TIA. ✌️
Beta Was this translation helpful? Give feedback.
All reactions