All Projects → luanbitar → gatsby-plugin-dynamic-routes

luanbitar / gatsby-plugin-dynamic-routes

Licence: CC0-1.0 License
Creating dynamic routes based on your environment and/or renaming existing routes

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to gatsby-plugin-dynamic-routes

ini
📝 Go INI config management. support multi file load, data override merge. parse ENV variable, parse variable reference. Dotenv file parse and loader. INI配置读取管理,支持多文件加载,数据覆盖合并, 解析ENV变量, 解析变量引用。DotEnv 解析加载
Stars: ✭ 72 (+414.29%)
Mutual labels:  environment, environment-variables, env
ts-dotenv
Strongly-typed environment variables for Node.js
Stars: ✭ 18 (+28.57%)
Mutual labels:  environment, environment-variables, env
gatsby-graphcms-example
Example of Gatsby source plugin for GraphCMS
Stars: ✭ 32 (+128.57%)
Mutual labels:  gatsby, gatsbyjs, gatsby-plugin
Universal Router
A simple middleware-style router for isomorphic JavaScript web apps
Stars: ✭ 1,598 (+11314.29%)
Mutual labels:  router, routes, routing
STCRouter
基于标准URL的iOS路由系统,可实现业务模块组件化,控制器之间零耦合,可实现黑白名单控制,可进行native降级到hybrid。
Stars: ✭ 19 (+35.71%)
Mutual labels:  router, routes, routing
dotenvy
Speed up your production sites by ditching .env for key/value variable pairs as Apache, Nginx, and shell equivalents
Stars: ✭ 31 (+121.43%)
Mutual labels:  environment, environment-variables, env
gatsby-attila-theme-ghost
A Gatsby theme plugin for creating blogs from headless Ghost CMS.
Stars: ✭ 16 (+14.29%)
Mutual labels:  gatsby, gatsbyjs, gatsby-plugin
Next Routes
Universal dynamic routes for Next.js
Stars: ✭ 2,354 (+16714.29%)
Mutual labels:  router, routes, routing
gatsby-plugin-prettier-build
prettify gatsby build output
Stars: ✭ 30 (+114.29%)
Mutual labels:  gatsby, gatsbyjs, gatsby-plugin
gatsby-plugin-lunr
Gatsby plugin for full text search implementation based on lunr client-side index. Supports multilanguage search.
Stars: ✭ 69 (+392.86%)
Mutual labels:  gatsby, gatsbyjs, gatsby-plugin
gatsby-theme-deck-n-blog
Create a deck (with mdx-deck) and a blog post from the same MDX
Stars: ✭ 17 (+21.43%)
Mutual labels:  gatsby, gatsbyjs, gatsby-plugin
router
Bidirectional Ring router. REST oriented. Rails inspired.
Stars: ✭ 78 (+457.14%)
Mutual labels:  router, routes, routing
routex.js
🔼 Alternative library to manage dynamic routes in Next.js
Stars: ✭ 38 (+171.43%)
Mutual labels:  router, routes, routing
gatsby-source-stripe
Gatsby source plugin for building websites using Stripe as a data source
Stars: ✭ 71 (+407.14%)
Mutual labels:  gatsby, gatsbyjs, gatsby-plugin
gatsby-plugin-apollo-client
📡Inject a Shopify Apollo Client into the browser.
Stars: ✭ 20 (+42.86%)
Mutual labels:  gatsby, gatsbyjs, gatsby-plugin
gatsby-plugin-disqus
💬 A plugin for adding Disqus comments to GatsbyJS
Stars: ✭ 40 (+185.71%)
Mutual labels:  gatsby, gatsbyjs, gatsby-plugin
subtle-ui
A collection of clever yet understated user interactions found on the web
Stars: ✭ 39 (+178.57%)
Mutual labels:  gatsby, gatsbyjs
gatsby-theme-gallery
🏞 A Gatsby Theme for adding a gallery to your site.
Stars: ✭ 40 (+185.71%)
Mutual labels:  gatsby, gatsby-plugin
gatsby-starter-antoine
My opinionated Gatsby.js starter
Stars: ✭ 17 (+21.43%)
Mutual labels:  gatsby, gatsbyjs
go router
The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
Stars: ✭ 380 (+2614.29%)
Mutual labels:  router, routing

Version Downloads Total

gatsby-plugin-dynamic-routes

Use 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.

Install

$ npm i gatsby-plugin-dynamic-routes

or

$ yarn add gatsby-plugin-dynamic-routes

How to use

Add the plugin to your gatsby-config.js.

module.exports = {
  plugins: [
    `gatsby-plugin-dynamic-routes`
  ]
}

Create your's Routes.js inside your src/ folder

project/
├── src/
  └── Routes.js

Routes.js

module.exports = {
  home: {
    path: `/casa`,
    component: `src/pages/Home.js`
  }
}

Use in client-side, include globals comment

component/Example.js

import { Link } from "gatsby"

function Example() {
  return <Link href="/casa" />
}

Dynamic routes

Routes.js

module.exports = {
  development: {
    two: {
      path: `/2`,
      component: `src/pages/Two.js`
    }
  },
  staging: {
    two: {
      path: `/dois`,
      component: `src/pages/Two.js`
    }
  },
  home: {
    path: `/casa`,
    component: `src/pages/Home.js`
  }
}

Run with your BUILD_ENV environment

BUILD_ENV=staging yarn start

If you are using the plugin Dynamic Environment Variables, 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.

component/Example.js

import { Link } from "gatsby"
/* globals ROUTES */

function Example() {
  return <Link href={ROUTES.two.path} />
}

Note that you need to put eslint globals comment in each file that will use ROUTES global variable.

You need to create an empty .eslintrc in root of your folder to remove this comments.

If you are using eslint in your project, just update this key to your config:

{
  "rules": {
    "no-undef": "off"
  }
}

You can pass more than path or component keys, these keys will be available in your component later

Variations

If you want to made variations of the same environment, but whit different routes, you can use ROUTE_ENV variable to chose your dynamic routes

example

ROUTE_ENV=organic BUILD_ENV=production yarn build

Options

routeFilePath

This options allows you to specify what's the path to your file with your Routes object

Example:

module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-dynamic-routes`,
      options: {
        routeFilePath: `config/Routes.js`
      }
    }
  ]
}
project/
├── config/
  └── Routes.js

If you want to put in root of your project, simply put the name of your file

Ignoring gatsby default page creator

By default, gatsby generates one route to each file inside pages/ folder, to disable this feature, put in you gatsby-config.js:

{
  resolve: `gatsby-plugin-page-creator`,
  options: {
    path: `${__dirname}/src/pages`,
    ignore: {
      patterns: [`**/*`],
    },
  },
},

Recommended plugins

Check out the Dynamic Environment Variables plugin that provides you to load different files based on your env variables

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].