Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with unplugin-auto-import #24

Closed
valgeirb opened this issue Jul 6, 2022 · 4 comments
Closed

Usage with unplugin-auto-import #24

valgeirb opened this issue Jul 6, 2022 · 4 comments

Comments

@valgeirb
Copy link

valgeirb commented Jul 6, 2022

Thanks for this plugin, it's really useful to get type hints for my routes.

I'm using unplugin-auto-import and was wondering what I should do to make these two plugin gel together. According to the docs, I should replace all my vue-router imports to @vue-router but that doesn't seem to work in vite.config.ts.

So my config looks something like this:

plugins: [
    vue(),
    AutoImport({
      imports: ['vue', 'vue-router'], // can't use @vue-router here
    }),
    VueRouter({
      routesFolder: 'src/pages',
    })
  ],

Things seem to mostly work, I get type hints for my routes this way in most places (doesn't seem to work when using $route in templates though)

Am I doing things wrong or is this ok?

Update:

Things seem to break when building, I get this error as an example:

Property 'isActive' does not exist on type 'RouteLocationResolvedTyped<RouteNamedMap, "/"> | RouteLocationResolvedTyped<RouteNamedMap, "/[...all]"> | ... 16 more ... | RouteLocationResolvedTyped<...>'.

14     <RouterLink :to="to" v-slot="{ isActive }" @click="close">

This can be fixed by manually importing RouterLink from @vue-router:

import { RouterLink } from '@vue-router'

but I'd rather have the auto-import plugin work for me instead.

@valgeirb
Copy link
Author

valgeirb commented Jul 6, 2022

Do we need a preset for this?

@edwardnyc
Copy link
Contributor

edwardnyc commented Jul 6, 2022

unplugin-auto-import. has presets with vue-router old version. you can rewrite it in the configuration file of auto-import

unplugin-auto-import preset pr
but Currently our functionality is not stable. I think we can wait and submit

@hi-reeve
Copy link
Contributor

hi-reeve commented Jul 6, 2022

it's coming soon #12

@posva posva closed this as completed in 3e71a23 Jul 6, 2022
@posva
Copy link
Owner

posva commented Jul 6, 2022

Added a section in the Readme for this and the two exports that exist for vue-router in unplugin-auto-import

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants