Created
December 5, 2020 02:42
-
-
Save cvan/8a57483ea59d1a2f4a6c4e52176e8126 to your computer and use it in GitHub Desktop.
is dynamic next.js route
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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