{"id":13506523,"url":"https://github.com/nuxt-community/router-module","last_synced_at":"2025-05-15T20:00:36.697Z","repository":{"id":24905712,"uuid":"102731799","full_name":"nuxt-community/router-module","owner":"nuxt-community","description":"Nuxt 2 module to use router.js instead of pages/ directory.","archived":false,"fork":false,"pushed_at":"2025-03-18T14:03:16.000Z","size":1674,"stargazers_count":396,"open_issues_count":30,"forks_count":28,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-11T13:48:10.714Z","etag":null,"topics":["nuxt","nuxt-module","router","vue-router"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nuxt-community.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-07T12:01:00.000Z","updated_at":"2025-03-15T20:58:49.000Z","dependencies_parsed_at":"2024-06-01T21:46:40.465Z","dependency_job_id":"c71845df-4048-4ae2-bd84-0310d760e5be","html_url":"https://github.com/nuxt-community/router-module","commit_stats":{"total_commits":191,"total_committers":18,"mean_commits":10.61111111111111,"dds":0.6492146596858639,"last_synced_commit":"7362f3834a9e3e8407a6a34f15885496f845b42c"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxt-community%2Frouter-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxt-community%2Frouter-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxt-community%2Frouter-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxt-community%2Frouter-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuxt-community","download_url":"https://codeload.github.com/nuxt-community/router-module/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414454,"owners_count":22067261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nuxt","nuxt-module","router","vue-router"],"created_at":"2024-08-01T01:00:53.205Z","updated_at":"2025-05-15T20:00:36.262Z","avatar_url":"https://github.com/nuxt-community.png","language":"TypeScript","funding_links":[],"categories":["Uncategorized","TypeScript"],"sub_categories":["Uncategorized"],"readme":"# @nuxtjs/router\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![Github Actions CI][github-actions-ci-src]][github-actions-ci-href]\n[![Codecov][codecov-src]][codecov-href]\n[![License][license-src]][license-href]\n\nNuxt 2 module to use router.js instead of pages/ directory\n\n[📖 **Release Notes**](./CHANGELOG.md)\n\n## Nuxt 3\n\nThis is now possible to extend `vue-router` with Nuxt 3 with different methods, learn more on https://nuxt.com/docs/guide/going-further/custom-routing\n\nIf you don't have the `pages/` directory, make sure to enable Vue Router with:\n\n```ts\nexport default defineNuxtConfig({\n  pages: true\n})\n```\n\n## Features\n\nUse your own `router.js` to handle your routes into your [Nuxt.js](https://nuxtjs.org) application.\n\n## Setup\n\n1. Add `@nuxtjs/router` dependency to your project\n\n```bash\nyarn add --dev @nuxtjs/router # or npm install --save-dev @nuxtjs/router\n```\n\n2. Add `@nuxtjs/router` to the `buildModules` section of `nuxt.config.js`\n\n```js\nexport default {\n  buildModules: [\n    // Simple usage\n    '@nuxtjs/router',\n\n    // With options\n    ['@nuxtjs/router', { /* module options */ }]\n  ]\n}\n```\n\n:warning: If you are using Nuxt **\u003c v2.9** you have to install the module as a `dependency` (No `--dev` or `--save-dev` flags) and use `modules` section in `nuxt.config.js` instead of `buildModules`.\n\n### Using top level options\n\n```js\nexport default {\n  buildModules: [\n    '@nuxtjs/router'\n  ],\n  routerModule: {\n    /* module options */\n  }\n}\n```\n\nIf you are using SPA mode, add an index `/` route to `generate` section of `nuxt.config.js`:\n\n```js\nexport default {\n  generate: {\n    routes: [\n      '/'\n    ]\n  }\n}\n```\n\n## Options\n\n### `path`\n\n- Type: `String`\n- Default: `srcDir`\n\nLocation of you route file.\n\n### `fileName`\n\n- Type: `String`\n- Default: `router.js`\n\nName of you route file.\n\n### `keepDefaultRouter`\n\n- Type: `Boolean`\n- Default: `false`\n\nCan access the default router.\n\n### `parsePages`\n\n- Type: `Boolean`\n- Default: `'keepDefaultRouter'`\n\nCan disable/enable the `pages/` directory into Nuxt.\n\n## Usage\n\nThis module, by default, disable the `pages/` directory into Nuxt and will use a `router.js` file at your `srcDir` directory:\n\n```bash\ncomponents/\n  my-page.vue\nrouter.js\n```\n\n`router.js` need to export a `createRouter` method like this:\n\n```js\nimport Vue from 'vue'\nimport Router from 'vue-router'\n\nimport MyPage from '~/components/my-page'\n\nVue.use(Router)\n\nexport function createRouter() {\n  return new Router({\n    mode: 'history',\n    routes: [\n      {\n        path: '/',\n        component: MyPage\n      }\n    ]\n  })\n}\n```\n\nThe components defined as routes have access to the same special attributes and functions (head, asyncData, validate, etc.) as the [Nuxt Page component](https://nuxtjs.org/guide/views/#pages).\n\n### Accessing default router\n\nIf you use the module with `{ keepDefaultRouter: true }`, you can access the default router:\n\n:warning: If you are using Nuxt `\u003c 2.9.0`, the parameter `routerOptions` is not available.\n\n:warning: If you are using Nuxt `\u003c 2.15.0`, the parameter `config` is not available.\n\n:warning: If you are using Nuxt `\u003c 2.16.0`, the parameter `store` is not available.\n\n```js\nexport function createRouter(ssrContext, createDefaultRouter, routerOptions, config, store) {\n  const options = routerOptions ? routerOptions : createDefaultRouter(ssrContext, config).options\n\n  return new Router({\n    ...options,\n    routes: fixRoutes(options.routes, store)\n  })\n}\n\nfunction fixRoutes(defaultRoutes, store) {\n  // default routes that come from `pages/`\n  // Filter some routes using the content of the store for example\n  return defaultRoutes.filter(...).map(...)\n}\n```\n\n## Development\n\n1. Clone this repository\n2. Install dependencies using `yarn install` or `npm install`\n3. Start development server using `npm run dev`\n\n## License\n\n[MIT License](./LICENSE)\n\nCopyright (c) Nuxt Community\n\n\u003c!-- Badges --\u003e\n[npm-version-src]: https://img.shields.io/npm/v/@nuxtjs/router/latest.svg\n[npm-version-href]: https://npmjs.com/package/@nuxtjs/router\n\n[npm-downloads-src]: https://img.shields.io/npm/dt/@nuxtjs/router.svg\n[npm-downloads-href]: https://npmjs.com/package/@nuxtjs/router\n\n[github-actions-ci-src]: https://github.com/nuxt-community/router-module/workflows/ci/badge.svg\n[github-actions-ci-href]: https://github.com/nuxt-community/router-module/actions?query=workflow%3Aci\n\n[codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/router-module.svg\n[codecov-href]: https://codecov.io/gh/nuxt-community/router-module\n\n[license-src]: https://img.shields.io/npm/l/@nuxtjs/router.svg\n[license-href]: https://npmjs.com/package/@nuxtjs/router\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuxt-community%2Frouter-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuxt-community%2Frouter-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuxt-community%2Frouter-module/lists"}