diff --git a/README.md b/README.md index 6b56ee255..aff03de08 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,26 @@ createRouter({ }) ``` +If you are using [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import), make sure to remove the `vue-router` preset and use the one exported by `unplugin-vue-router`: + +```diff + import { defineConfig } from 'vite' + import AutoImport from 'unplugin-auto-import/vite' ++import { VueRouterExports } from 'unplugin-vue-router' + + export default defineConfig({ + plugins: [ + // other plugins + AutoImport({ + imports: [ +- 'vue-router', ++ { '@vue-router': VueRouterExports }, + ], + }), + ], + }) +``` + Make sure to also check and follow [the TypeScript section](#typescript) below **if you are using TypeScript or have a `jsconfig.json` file**. ## Configuration diff --git a/package.json b/package.json index 28501b5fc..b71573f0f 100644 --- a/package.json +++ b/package.json @@ -118,6 +118,7 @@ "ts-expect": "^1.3.0", "tsup": "^6.1.3", "typescript": "^4.7.4", + "unplugin-auto-import": "^0.9.2", "vite": "^2.9.13", "vitest": "^0.17.0", "vue": "^3.2.37", diff --git a/playground/auto-imports.d.ts b/playground/auto-imports.d.ts new file mode 100644 index 000000000..096d0c3d3 --- /dev/null +++ b/playground/auto-imports.d.ts @@ -0,0 +1,6 @@ +// Generated by 'unplugin-auto-import' +export {} +declare global { + const useRoute: typeof import('@vue-router')['useRoute'] + const useRouter: typeof import('@vue-router')['useRouter'] +} diff --git a/playground/src/routes/[name].vue b/playground/src/routes/[name].vue index a9afe054e..b1a3646be 100644 --- a/playground/src/routes/[name].vue +++ b/playground/src/routes/[name].vue @@ -1,10 +1,5 @@