Gathering detailed insights and metrics for vite-plugin-pages
Gathering detailed insights and metrics for vite-plugin-pages
Gathering detailed insights and metrics for vite-plugin-pages
Gathering detailed insights and metrics for vite-plugin-pages
@uni-helper/vite-plugin-uni-pages
File system based routing for uni-app applications using Vite
vite-plugin-react-pages
<p> <a href="https://www.npmjs.com/package/vite-plugin-react-pages" target="_blank" rel="noopener"><img src="https://img.shields.io/npm/v/vite-plugin-react-pages.svg" alt="npm package" /></a> </p>
vite-plugin-multi-pages
Multi Page for vite
vite-plugin-pages-sitemap
vite-plugin-pages based sitemap generator
File system based route generator for ⚡️Vite
npm install vite-plugin-pages
Typescript
Module System
Node Version
NPM Version
TypeScript (98.19%)
Dockerfile (1.61%)
JavaScript (0.12%)
Vue (0.07%)
Total Downloads
6,163,227
Last Day
11,406
Last Week
67,314
Last Month
234,641
Last Year
2,263,118
MIT License
1,980 Stars
940 Commits
131 Forks
6 Watchers
7 Branches
45 Contributors
Updated on May 09, 2025
Latest Version
0.33.0
Package Id
vite-plugin-pages@0.33.0
Unpacked Size
256.86 kB
Size
63.52 kB
File Count
12
NPM Version
10.9.2
Node Version
22.14.0
Published on
Mar 29, 2025
Cumulative downloads
Total Downloads
Last Day
34.3%
11,406
Compared to previous day
Last Week
14.3%
67,314
Compared to previous week
Last Month
3.4%
234,641
Compared to previous month
Last Year
16.2%
2,263,118
Compared to previous year
10
2
File system based routing for Vue 3 / React / Solid applications using Vite
🚨Important Notes🚨
We recommend that Vue users use unplugin-vue-router instead of this plugin.
unplugin-vue-router is a unplugin library created by @posva, same auther as vue-router. It provide almost same feature as vite-plugin-pages but better intergration with vue-router, include some cool feature like auto generate route types base on your route files to provide autocomplete for vue-router.
1npm install -D vite-plugin-pages 2npm install vue-router
since v0.19.0 we only support react-router v6, if you are using react-router v5 use v0.18.2.
1npm install -D vite-plugin-pages 2npm install react-router react-router-dom
1npm install -D vite-plugin-pages 2npm install @solidjs/router
Add to your vite.config.js
:
1import Pages from 'vite-plugin-pages' 2 3export default { 4 plugins: [ 5 // ... 6 Pages(), 7 ], 8}
By default a page is a Vue component exported from a .vue
or .js
file in the
src/pages
directory.
You can access the generated routes by importing the ~pages
module in your application.
1import { createRouter } from 'vue-router' 2import routes from '~pages' 3 4const router = createRouter({ 5 // ... 6 routes, 7})
Type
1// vite-env.d.ts 2/// <reference types="vite-plugin-pages/client" />
experimental
1import { StrictMode, Suspense } from 'react' 2import { createRoot } from 'react-dom/client' 3import { 4 BrowserRouter, 5 useRoutes, 6} from 'react-router-dom' 7 8import routes from '~react-pages' 9 10function App() { 11 return ( 12 <Suspense fallback={<p>Loading...</p>}> 13 {useRoutes(routes)} 14 </Suspense> 15 ) 16} 17 18const app = createRoot(document.getElementById('root')!) 19 20app.render( 21 <StrictMode> 22 <BrowserRouter> 23 <App /> 24 </BrowserRouter> 25 </StrictMode>, 26)
Type
1// vite-env.d.ts 2/// <reference types="vite-plugin-pages/client-react" />
This guide is for solid-router v0.10.x and newer. For older versions see the migration guide.
1import { Router } from '@solidjs/router' 2import { render } from 'solid-js/web' 3import routes from '~solid-pages' 4 5render( 6 () => { 7 return ( 8 <Router 9 root={props => ( 10 <Suspense> 11 {props.children} 12 </Suspense> 13 )} 14 > 15 {routes} 16 </Router> 17 ) 18 }, 19 document.getElementById('root') as HTMLElement, 20)
Remember to check the dirs
is set to the correct routes directory in vite.config.ts
:
1import { defineConfig } from 'vite' 2import Pages from 'vite-plugin-pages' 3import solidPlugin from 'vite-plugin-solid' 4 5export default defineConfig({ 6 plugins: [ 7 Pages({ 8 dirs: ['src/pages'], 9 }), 10 solidPlugin() 11 ], 12})
Type
1// vite-env.d.ts 2/// <reference types="vite-plugin-pages/client-solid" />
To use custom configuration, pass your options to Pages when instantiating the plugin:
1// vite.config.js 2import Pages from 'vite-plugin-pages' 3 4export default { 5 plugins: [ 6 Pages({ 7 dirs: 'src/views', 8 }), 9 ], 10}
string | (string | PageOptions)[]
'src/pages'
Paths to the pages directory. Supports globs.
Can be:
/
/
PageOptions
, Check below 👇1interface PageOptions { 2 /** 3 * Page base directory. 4 * @default 'src/pages' 5 */ 6 dir: string 7 /** 8 * Page base route. 9 */ 10 baseRoute: string 11 /** 12 * Page file pattern. 13 * @example `**\/*.page.vue` 14 */ 15 filePattern?: string 16}
Specifying a glob or an array of PageOptions
allow you to use multiple
pages folder, and specify the base route to append to the path and the route
name.
Additionally, you can specify a filePattern
to filter the files that will be used as pages.
Folder structure
1src/ 2 ├── features/ 3 │ └── dashboard/ 4 │ ├── code/ 5 │ ├── components/ 6 │ └── pages/ 7 ├── admin/ 8 │ ├── code/ 9 │ ├── components/ 10 │ └── pages/ 11 └── pages/
Config
1// vite.config.js 2export default { 3 plugins: [ 4 Pages({ 5 dirs: [ 6 // basic 7 { dir: 'src/pages', baseRoute: '' }, 8 // features dir for pages 9 { dir: 'src/features/**/pages', baseRoute: 'features' }, 10 // with custom file pattern 11 { dir: 'src/admin/pages', baseRoute: 'admin', filePattern: '**/*.page.*' }, 12 ], 13 }), 14 ], 15}
string[]
['vue', 'ts', 'js']
['tsx', 'jsx', 'ts', 'js']
['tsx', 'jsx', 'ts', 'js']
An array of valid file extensions for pages. If multiple extensions match for a file, the first one is used.
string[]
[]
An array of glob patterns to exclude matches.
1# folder structure 2src/pages/ 3 ├── users/ 4 │ ├── components 5 │ │ └── form.vue 6 │ ├── [id].vue 7 │ └── index.vue 8 └── home.vue
1// vite.config.js 2export default { 3 plugins: [ 4 Pages({ 5 exclude: ['**/components/*.vue'], 6 }), 7 ], 8}
'sync' | 'async' | (filepath: string, pluginOptions: ResolvedOptions) => 'sync' | 'async')
'sync'
, others: async
.Import mode can be set to either async
, sync
, or a function which returns
one of those values.
To get more fine-grained control over which routes are loaded sync/async, you can use a function to resolve the value based on the route path. For example:
1// vite.config.js 2export default { 3 plugins: [ 4 Pages({ 5 importMode(filepath, options) { 6 // default resolver 7 // for (const page of options.dirs) { 8 // if (page.baseRoute === '' && filepath.startsWith(`/${page.dir}/index`)) 9 // return 'sync' 10 // } 11 // return 'async' 12 13 // Load about page synchronously, all other pages are async. 14 return filepath.includes('about') ? 'sync' : 'async' 15 }, 16 }), 17 ], 18}
If you are using async
mode with react-router
, you will need to wrap your route components with Suspense
:
1function App() { 2 return ( 3 <Suspense fallback={<p>Loading...</p>}> 4 {useRoutes(routes)} 5 </Suspense> 6 ) 7}
'absolute' | 'relative'
'relative'
Import page components from absolute or relative paths. The default behavior is to import from relative paths, but in some special cases, it can be set to 'absolute'
to import from absolute paths.
For example, if your page components are located in the app/pages
directory and you have set base: /app/
in your vite.config.js
, you should set importPath
to 'absolute'
in order to correctly import the page components.
1// vite.config.js 2export default { 3 base: '/app/', 4 plugins: [ 5 Pages({ 6 dirs: 'app/pages', 7 8 // It should be set to 'absolute' in this case. 9 importPath: 'absolute', 10 }), 11 ], 12}
See #492 for more details.
string
'json5'
Default SFC route block parser.
'next' | 'nuxt' | 'remix'
next
Use file system dynamic routing supporting:
string
-
Separator for generated route names.
'vue' | 'react' | 'solid' | PageResolver
'auto detect'
Route resolver, support vue
, react
, solid
or custom PageResolver
.
string
'~pages'
'~react-pages'
'~solid-pages'
Module id for routes import, useful when you what to use multiple pages plugin in one project.
(route: any, parent: any | undefined) => any | void
A function that takes a route and optionally returns a modified route. This is useful for augmenting your routes with extra data (e.g. route metadata).
1// vite.config.js 2export default { 3 // ... 4 plugins: [ 5 Pages({ 6 extendRoute(route, parent) { 7 if (route.path === '/') { 8 // Index is unauthenticated. 9 return route 10 } 11 12 // Augment the route with meta that indicates that the route requires authentication. 13 return { 14 ...route, 15 meta: { auth: true }, 16 } 17 }, 18 }), 19 ], 20}
(routes: any[]) => Awaitable<any[] | void>
A function that takes a generated routes and optionally returns a modified generated routes.
(clientCode: string) => Awaitable<string | void>
A function that takes a generated client code and optionally returns a modified generated client code.
Add route meta to the route by adding a <route>
block to the SFC. This will be
directly added to the route after it is generated, and will override it.
You can specific a parser to use using <route lang="yaml">
, or set a default
parser using routeBlockLang
option.
JSON/JSON5:
1<route> 2{ 3 name: "name-override", 4 meta: { 5 requiresAuth: false 6 } 7} 8</route>
YAML:
1<route lang="yaml"> 2name: name-override 3meta: 4 requiresAuth: true 5</route>
<route>
To enable syntax highlighting <route>
in VS Code using Vetur's Custom Code Blocks add the following snippet to your preferences...
"vetur.grammar.customBlocks": {
"route": "json"
}
Vetur: Generate grammar from vetur.grammar.customBlocks
Add route meta to the route by adding a comment block starts with route
to the JSX or TSX file(In Vue). This will be directly added to the route after it is generated, and will override it.
This feature only support JSX/TSX in vue, and will parse only the first block of comments which should also start with route
.
Now only yaml
parser supported.
'vue'
1/* 2route 3 4name: name-override 5meta: 6 requiresAuth: false 7 id: 1234 8 string: "1234" 9*/
Inspired by the routing from NuxtJS 💚
Pages automatically generates an array of routes for you to plug-in to your
instance of Vue Router. These routes are determined by the structure of the
files in your pages directory. Simply create .vue
files in your pages
directory and routes will automatically be created for you, no additional
configuration required!
For more advanced use cases, you can tailor Pages to fit the needs of your app through configuration.
Pages will automatically map files from your pages directory to a route with the same name:
src/pages/users.vue
-> /users
src/pages/users/profile.vue
-> /users/profile
src/pages/settings.vue
-> /settings
Files with the name index
are treated as the index page of a route:
src/pages/index.vue
-> /
src/pages/users/index.vue
-> /users
Dynamic routes are denoted using square brackets. Both directories and pages can be dynamic:
src/pages/users/[id].vue
-> /users/:id
(/users/one
)src/pages/[user]/settings.vue
-> /:user/settings
(/one/settings
)Any dynamic parameters will be passed to the page as props. For example, given
the file src/pages/users/[id].vue
, the route /users/abc
will be passed the
following props:
1{ "id": "abc" }
We can make use of Vue Routers child routes to create nested layouts. The parent component can be defined by giving it the same name as the directory that contains your child routes.
For example, this directory structure:
src/pages/
├── users/
│ ├── [id].vue
│ └── index.vue
└── users.vue
will result in this routes configuration:
1[ 2 { 3 "path": "/users", 4 "component": "/src/pages/users.vue", 5 "children": [ 6 { 7 "path": "", 8 "component": "/src/pages/users/index.vue", 9 "name": "users" 10 }, 11 { 12 "path": ":id", 13 "component": "/src/pages/users/[id].vue", 14 "name": "users-id" 15 } 16 ] 17 } 18]
Catch-all routes are denoted with square brackets containing an ellipsis:
src/pages/[...all].vue
-> /*
(/non-existent-page
)The text after the ellipsis will be used both to name the route, and as the name of the prop in which the route parameters are passed.
If you need to generate a sitemap from generated routes, you can use vite-plugin-pages-sitemap. This plugin allow you to automatically generate sitemap.xml and robots.xml files with customization.
MIT License © 2021-PRESENT hannoeru
No vulnerabilities found.
Reason
30 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
2 existing vulnerabilities detected
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
Found 0/11 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More