
Product
Introducing Socket Scanning for OpenVSX Extensions
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.
unplugin-vue-router
Advanced tools
Zero-config File based type safe Routing
This build-time plugin simplifies your routing setup and makes it safer and easier to use thanks to TypeScript.
⚠️ This package is still experimental. If you found any issue, design flaw, or have ideas to improve it, please, open an issue or a Discussion.
npm i unplugin-vue-router
// vite.config.ts
import VueRouter from 'unplugin-vue-router/vite'
export default defineConfig({
plugins: [
VueRouter({
/* options */
}),
],
})
Example: playground/
// rollup.config.js
import VueRouter from 'unplugin-vue-router/rollup'
export default {
plugins: [
VueRouter({
/* options */
}),
],
}
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-vue-router/webpack')({
/* options */
}),
],
}
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-vue-router/webpack')({
/* options */
}),
],
},
}
Then you can replace your imports from vue-router to @vue-router:
-import { createRouter, createWebHistory } from 'vue-router'
+import { createRouter, createWebHistory } from '@vue-router'
createRouter({
history: createWebHistory(),
// You don't need to pass the routes anymore,
// the plugin writes it for you 🤖
})
Make sure to also check the TypeScript section below if you are using TypeScript.
Have a glimpse of all the existing configuration options with their corresponding default values:
VueRouter({
// Folder(s) to scan for vue components and generate routes. Can be a string or an array of strings.
routesFolder: 'src/routes'
// Path for the generated types. Defaults to `./typed-router.d.ts` if typescript
// is installed. Can be disabled by passing `false`.
dts: './typed-router.d.ts',
})
This plugin generates a d.ts file with all the typing overrides. Make sure to include it in your tsconfig.json's include or files property:
{
// ...
"include": [/* ... */ "typed-router.d.ts"]
// ...
}
Make sure to import from @vue-router to get access to the typed APIs instead of vue-router. You can commit the typed-router.d.ts file to your repository to make your life easier.
This project idea came from trying to type the router directly using Typescript, finding out it's not fast enough to be pleasant to use and, ending up using build-based tools, taking some inspiration from other projects like:
vue-router is the official router for Vue.js. It provides a comprehensive set of features for routing in Vue.js applications, including nested routes, route guards, and dynamic routing. Compared to unplugin-vue-router, vue-router requires more manual setup for route definitions but offers a high level of customization.
vite-plugin-pages is a Vite plugin that automatically generates routes based on the file structure of your project. It is similar to unplugin-vue-router in that it simplifies route management, but it is specifically designed to work with Vite, a build tool that is often used with Vue.js.
FAQs
File based typed routing for Vue Router
The npm package unplugin-vue-router receives a total of 828,482 weekly downloads. As such, unplugin-vue-router popularity was classified as popular.
We found that unplugin-vue-router demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.

Product
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies