{"id":14963027,"url":"https://github.com/luanbitar/gatsby-plugin-dynamic-routes","last_synced_at":"2025-10-25T00:31:46.597Z","repository":{"id":36700780,"uuid":"229771463","full_name":"luanbitar/gatsby-plugin-dynamic-routes","owner":"luanbitar","description":"Creating dynamic routes based on your environment and/or renaming existing routes","archived":false,"fork":false,"pushed_at":"2023-10-11T00:08:24.000Z","size":16,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T04:43:34.755Z","etag":null,"topics":["dynamic","env","environment","environment-variables","gatsby","gatsby-plugin","gatsbyjs","plugin","plugins","router","routes","routing"],"latest_commit_sha":null,"homepage":"https://www.gatsbyjs.org/packages/gatsby-plugin-dynamic-routes/?=routes","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luanbitar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"luanbitar"}},"created_at":"2019-12-23T14:49:08.000Z","updated_at":"2024-07-13T00:59:25.000Z","dependencies_parsed_at":"2023-12-20T13:24:49.309Z","dependency_job_id":null,"html_url":"https://github.com/luanbitar/gatsby-plugin-dynamic-routes","commit_stats":{"total_commits":11,"total_committers":3,"mean_commits":"3.6666666666666665","dds":"0.18181818181818177","last_synced_commit":"7246887332ac736dcdabee89955e0e3bdfbb020a"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luanbitar%2Fgatsby-plugin-dynamic-routes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luanbitar%2Fgatsby-plugin-dynamic-routes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luanbitar%2Fgatsby-plugin-dynamic-routes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luanbitar%2Fgatsby-plugin-dynamic-routes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luanbitar","download_url":"https://codeload.github.com/luanbitar/gatsby-plugin-dynamic-routes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238053514,"owners_count":19408699,"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":["dynamic","env","environment","environment-variables","gatsby","gatsby-plugin","gatsbyjs","plugin","plugins","router","routes","routing"],"created_at":"2024-09-24T13:30:55.865Z","updated_at":"2025-10-25T00:31:46.277Z","avatar_url":"https://github.com/luanbitar.png","language":"JavaScript","funding_links":["https://github.com/sponsors/luanbitar"],"categories":[],"sub_categories":[],"readme":"[![Version](https://img.shields.io/npm/v/gatsby-plugin-dynamic-routes.svg)](https://www.npmjs.com/package/gatsby-plugin-dynamic-routes)\n[![Downloads Total](https://img.shields.io/npm/dt/gatsby-plugin-dynamic-routes.svg)](https://www.npmjs.com/package/gatsby-plugin-dynamic-routes)\n\n# gatsby-plugin-dynamic-routes\n\nUse one file to declare your routes, provides to chose dynamic route paths based on your `BUILD_ENV` or `ROUTE_ENV` to your custom routing env. Also it's possible to only renaming routes on `pages/`, or use everything together.\n\n## Install\n\n`$ npm i gatsby-plugin-dynamic-routes`\n\nor\n\n`$ yarn add gatsby-plugin-dynamic-routes`\n\n## How to use\n\nAdd the plugin to your `gatsby-config.js`.\n\n```javascript\nmodule.exports = {\n  plugins: [\n    `gatsby-plugin-dynamic-routes`\n  ]\n}\n```\n\nCreate your's `Routes.js` inside your `src/` folder\n\n```bash\nproject/\n├── src/\n  └── Routes.js\n```\n\n`Routes.js`\n\n```javascript\nmodule.exports = {\n  home: {\n    path: `/casa`,\n    component: `src/pages/Home.js`\n  }\n}\n```\n\nUse in client-side, include globals comment\n\n`component/Example.js`\n\n```javascript\nimport { Link } from \"gatsby\"\n\nfunction Example() {\n  return \u003cLink href=\"/casa\" /\u003e\n}\n```\n\n## Dynamic routes\n\n`Routes.js`\n\n```javascript\nmodule.exports = {\n  development: {\n    two: {\n      path: `/2`,\n      component: `src/pages/Two.js`\n    }\n  },\n  staging: {\n    two: {\n      path: `/dois`,\n      component: `src/pages/Two.js`\n    }\n  },\n  home: {\n    path: `/casa`,\n    component: `src/pages/Home.js`\n  }\n}\n```\n\nRun with your `BUILD_ENV` environment\n\n```bash\nBUILD_ENV=staging yarn start\n```\n\nIf you are using the plugin [Dynamic Environment Variables][1], what will happen is that your environments inside your `.env` and `.env.staging` will be loaded, and your routes inside `staging` key will go to root of the object that is exported of `Routes` and will be available in yours global environment variables.\n\n`component/Example.js`\n\n```javascript\nimport { Link } from \"gatsby\"\n/* globals ROUTES */\n\nfunction Example() {\n  return \u003cLink href={ROUTES.two.path} /\u003e\n}\n```\n\nNote that you need to put `eslint globals comment` in each file that will use `ROUTES` global variable.\n\nYou need to create an empty `.eslintrc` in root of your folder to remove this comments.\n\nIf you are using eslint in your project, just update this key to your config:\n\n```javascript\n{\n  \"rules\": {\n    \"no-undef\": \"off\"\n  }\n}\n```\n\nYou can pass more than `path` or `component` keys, these keys will be available in your component later\n\n## Variations\n\nIf you want to made variations of the same environment, but whit different routes, you can use `ROUTE_ENV` variable to chose your dynamic routes\n\n`example`\n\n```bash\nROUTE_ENV=organic BUILD_ENV=production yarn build\n```\n\n## Options\n\n### `routeFilePath`\n\nThis options allows you to specify what's the path to your file with your Routes object\n\nExample:\n\n```javascript\nmodule.exports = {\n  plugins: [\n    {\n      resolve: `gatsby-plugin-dynamic-routes`,\n      options: {\n        routeFilePath: `config/Routes.js`\n      }\n    }\n  ]\n}\n```\n\n```bash\nproject/\n├── config/\n  └── Routes.js\n```\n\nIf you want to put in root of your project, simply put the name of your file\n\n## Ignoring gatsby default page creator\n\nBy default, gatsby generates one route to each file inside `pages/` folder, to disable this feature, put in you `gatsby-config.js`:\n\n```js\n{\n  resolve: `gatsby-plugin-page-creator`,\n  options: {\n    path: `${__dirname}/src/pages`,\n    ignore: {\n      patterns: [`**/*`],\n    },\n  },\n},\n```\n\n## Recommended plugins\n\nCheck out the [Dynamic Environment Variables][1] plugin that provides you to load different files based on your env variables\n\n[1]: https://github.com/luanbitar/gatsby-env-variables\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluanbitar%2Fgatsby-plugin-dynamic-routes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluanbitar%2Fgatsby-plugin-dynamic-routes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluanbitar%2Fgatsby-plugin-dynamic-routes/lists"}