Skip to content

Instantly share code, notes, and snippets.

@cvan
Created December 5, 2020 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvan/8a57483ea59d1a2f4a6c4e52176e8126 to your computer and use it in GitHub Desktop.
Save cvan/8a57483ea59d1a2f4a6c4e52176e8126 to your computer and use it in GitHub Desktop.
is dynamic next.js route
/**
* Identify `/[param]/` in route string.
* @see https://github.com/vercel/next.js/blob/master/packages/next/next-server/lib/router/utils/is-dynamic.ts#L7
*
* @param {route} The value from next/router's `route.asPath` (e.g., `/browse/[listingId]`).
* @returns {boolean} True if the route looks like a Next.js dynamic route.
*/
const TEST_ROUTE = /\/\[[^/]+?\](?=\/|$)/;
export function isDynamicRoute(route) {
return TEST_ROUTE.test(route);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment