Gatsby plugin for creating paths that exist only on the client
npx @tessl/cli install tessl/npm-gatsby-plugin-create-client-paths@4.9.0Note: This plugin became obsolete in recent versions of Gatsby. Modern Gatsby applications should use the File System Route API with catch-all routes ([...].js) instead.
Gatsby plugin for creating "hybrid" applications that combine statically rendered pages with client-only routes. These client-only paths exist on the client side and do not correspond to physical HTML files in the built assets, enabling dynamic application sections alongside static content.
npm install gatsby-plugin-create-client-pathsThis plugin is configured in gatsby-config.js and works through Gatsby's plugin system. There are no direct imports or API calls - the plugin operates through Gatsby's build-time lifecycle hooks, specifically onCreatePage, which is called for every page Gatsby discovers during the build process.
Plugin Configuration:
// gatsby-config.js
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-create-client-paths',
options: {
prefixes: ['/app/*', '/dashboard/*', '/profile/*']
}
}
]
}// gatsby-config.js - Single client path
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-create-client-paths',
options: {
prefixes: ['/app/*']
}
}
]
}With this configuration:
/app/ become client-only routessrc/pages/app.js handles all /app/* paths/app/* spaceThis plugin integrates with Gatsby's build-time page creation process through the onCreatePage lifecycle hook:
gatsby-config.js with path prefix patternsonCreatePage for each discovered pagematchPath property set, enabling client-side routingThe plugin operates entirely at build time - there's no runtime JavaScript added to the client bundle. It modifies Gatsby's internal page objects during the build process to enable client-side routing for specified path patterns.
Configures the plugin through Gatsby's plugin system with path prefix patterns.
/**
* Plugin options configuration object
*/
interface PluginOptions {
/** Array of path prefix patterns for client-only routes. Must be glob patterns ending with '/*' */
prefixes: string[];
}Prefix Pattern Requirements:
/ (forward slash)/* (glob pattern)'/app/*', '/dashboard/*', '/auth/*''app/*', '/app', '/app/**'The plugin implements Gatsby's onCreatePage lifecycle hook to process pages and configure client-only routing.
/**
* Gatsby onCreatePage lifecycle hook implementation
* Processes pages to set up client-only routing for matching prefixes
* @param pluginArgs - Gatsby page creation context
* @param pluginOptions - Plugin configuration options
*/
function onCreatePage(
pluginArgs: {
page: {
path: string;
matchPath?: string;
};
actions: {
createPage: (page: object) => void;
};
},
pluginOptions: PluginOptions
): void;The plugin validates prefix patterns during execution and throws errors for invalid patterns:
/**
* Validation error thrown for invalid prefix patterns
* Thrown when prefix doesn't match required format: /path/*
*/
class Error {
constructor(message: string);
}Common Validation Errors:
/: "app/*" → Invalid
Error: Plugin "gatsby-plugin-create-client-paths" found invalid prefix pattern: app/*/*: "/app" → Invalid
Error: Plugin "gatsby-plugin-create-client-paths" found invalid prefix pattern: /app"/app/path" → Invalid
Error: Plugin "gatsby-plugin-create-client-paths" found invalid prefix pattern: /app/path"" → Invalid"/app/*/*" → InvalidTroubleshooting:
/path/*/*gatsby-config.jsLegacy (this plugin):
// gatsby-config.js
{
resolve: 'gatsby-plugin-create-client-paths',
options: { prefixes: ['/app/*'] }
}Modern Gatsby (File System Route API):
/src
/pages
/app
[...].js // Handles all /app/* routesThe modern approach eliminates the need for this plugin by providing native support for client-only routes through the file system.
Multiple Client Paths:
// gatsby-config.js
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-create-client-paths',
options: {
prefixes: [
'/app/*', // Main application
'/admin/*', // Admin panel
'/dashboard/*' // User dashboard
]
}
}
]
}E-commerce Example:
// gatsby-config.js
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-create-client-paths',
options: {
prefixes: [
'/account/*', // User account pages
'/checkout/*', // Checkout flow
'/cart/*' // Shopping cart
]
}
}
]
}Each prefix requires a corresponding page component at src/pages/[prefix-name].js to handle the client-only routing.