Registry / web-framework / vue-auto-routing

vue-auto-routing

JSON →
library1.0.1jsnpmunverified

vue-auto-routing is a JavaScript library designed for automatically generating Vue Router routes by convention, mimicking the file-system-based routing approach popularized by frameworks like Nuxt.js. It leverages `vue-route-generator` under the hood to transform component files within a specified directory (e.g., `src/pages`) into a Vue Router configuration. The library ships with a Webpack plugin that integrates into the build process to dynamically generate these routes. As of its current stable version `1.0.1`, it supports both Vue 2 and Vue 3 projects, with `v1.0.0` introducing official Vue 3 compatibility. While `vue-auto-routing` provides the core generation logic, users often prefer `vue-cli-plugin-auto-routing` for a more integrated setup within Vue CLI projects, which includes additional features like automatic layout resolution. The library has a moderate release cadence, focusing on compatibility and core feature enhancements.

npm install vue-auto-routing
INSTALL
IMPORT
SIG · VUE-AUTO-ROUTING
V
vue-auto-routing
web-frameworkjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

routes
import routes from 'vue-auto-routing';
const routes = require('vue-auto-routing');
This import path 'vue-auto-routing' is a virtual module handled by the Webpack plugin, resolving to the generated array of Vue Router route objects. Do not attempt to dynamically require it.
VueAutoRoutingPlugin
import VueAutoRoutingPlugin from 'vue-auto-routing/lib/webpack-plugin';
import { VueAutoRoutingPlugin } from 'vue-auto-routing/lib/webpack-plugin';
The plugin is a default export from its specific path. In typical Webpack configuration files, CommonJS `require` syntax is also very common: `const VueAutoRoutingPlugin = require('vue-auto-routing/lib/webpack-plugin');`

Demonstrates how to integrate `vue-auto-routing` by configuring its Webpack plugin and consuming the generated routes in a Vue 3 application's router setup. Includes a minimal Webpack configuration example.

import { createApp } from 'vue'; import { createRouter, createWebHistory } from 'vue-router'; import App from './App.vue'; // This 'routes' import is a virtual module provided by vue-auto-routing's Webpack plugin. // It dynamically contains the generated route configurations based on your 'pages' directory. import routes from 'vue-auto-routing'; // 1. Configure Vue Router with the automatically generated routes (for Vue 3) const router = createRouter({ history: createWebHistory(), routes, }); // 2. Mount your Vue 3 application createApp(App).use(router).mount('#app'); // --- webpack.config.js (or vue.config.js if using Vue CLI) --- const VueAutoRoutingPlugin = require('vue-auto-routing/lib/webpack-plugin'); const path = require('path'); module.exports = { // ... other webpack configurations ... plugins: [ new VueAutoRoutingPlugin({ pages: path.resolve(__dirname, 'src/pages'), // REQUIRED: Path to your page components directory importPrefix: '@/pages/', // OPTIONAL: Prefix for importing components in generated routes (e.g., '@/pages/Home.vue') // output: 'src/router/generated-routes.js', // OPTIONAL: Specify a physical output file for inspection or explicit import }), ], resolve: { alias: { '@': path.resolve(__dirname, 'src'), // Ensure '@' alias is configured if used in importPrefix }, }, }; /* Example: src/pages/About.vue <template> <div>About Page</div> </template> <route> { "meta": { "title": "About Us" } } </route> */
Debug
Known issues
breakingThe `<route-meta>` custom block for defining route metadata has been deprecated in favor of the `<route>` custom block. It will no longer be processed by the route generator and might lead to ignored metadata.
fix
Migrate all route metadata definitions from `<route-meta>` to the new `<route>` custom block format within your Vue components. For example, change `<route-meta>{ ... }</route-meta>` to `<route>{ "meta": { ... } }</route>`.
affects: >=0.5.0
breakingRoute names generated for `index.vue` components no longer include the `-index` suffix. For instance, a component located at `/users/index.vue` will now generate a route with the name `users` instead of `users-index`.
fix
Update any hardcoded route names used for programmatic navigation (e.g., `router.push({ name: 'users-index' })`) or component lookups to remove the `-index` suffix.
affects: >=0.5.0
gotchaWhile `vue-auto-routing` generates routes compatible with both Vue 2 and Vue 3, the application's Vue Router initialization and mounting process differs significantly between the two major Vue versions.
fix
For Vue 2 applications, use `Vue.use(Router)` and instantiate the router with `new Router({ routes })`. For Vue 3, ensure you import `createRouter` and `createWebHistory` from `vue-router`, create the router instance, and then use `app.use(router)` after creating your app with `createApp`.
affects: >=1.0.0
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'vue-auto-routing' in '[path]'
This error typically means the `vue-auto-routing` virtual module (which represents the generated routes) is not being correctly resolved by Webpack. This can be due to an incorrect `VueAutoRoutingPlugin` configuration or missing aliases.
fix
Ensure `VueAutoRoutingPlugin` is correctly installed and configured in your `webpack.config.js`. Verify that the `pages` option points to an existing directory. If you've specified an `output` option for the plugin, ensure your import path matches that output file.
TypeError: (0 , vue_1.createApp)().use is not a function
This usually indicates a fundamental mismatch in how Vue and Vue Router are being initialized, specifically trying to use a Vue 3 `createApp` method with a Vue 2 Router instance, or vice-versa.
fix
Verify that your `vue` and `vue-router` package versions are compatible. For Vue 3, always use `createRouter` and `createWebHistory` from `vue-router`, and mount your application using `createApp(App).use(router)`.
Error: [VueAutoRoutingPlugin] 'pages' option must be a string path to a directory.
The `pages` option in your `VueAutoRoutingPlugin` configuration is either missing, empty, or points to a non-existent or invalid directory. The plugin cannot find the components to generate routes from.
fix
Provide a valid string path to your components directory (e.g., `'src/pages'`) for the `pages` option within the `VueAutoRoutingPlugin` configuration in your webpack setup.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
webpackrequiredRequired for the `VueAutoRoutingPlugin` to integrate into the build process.
vue-routerrequiredPeer dependency as it generates routes directly consumable by Vue Router.
vuerequiredPeer dependency for the Vue application itself.
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
vue-auto-routing — npm install vue-auto-routing · libregistry