Download next.js/packages/next/src/server/lib/to-route.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 558 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/server/lib/to-route.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/server/lib/to-route.ts
-
curl -L -o to-route.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/server/lib/to-route.ts
558 Bytes
| /** | |
| * This transforms a URL pathname into a route. It removes any trailing slashes | |
| * and the `/index` suffix. | |
| * | |
| * @param pathname - The URL path that needs to be optimized. | |
| * @returns - The route | |
| * | |
| * @example | |
| * // returns '/example' | |
| * toRoute('/example/index/'); | |
| * | |
| * @example | |
| * // returns '/example' | |
| * toRoute('/example/'); | |
| * | |
| * @example | |
| * // returns '/' | |
| * toRoute('/index/'); | |
| * | |
| * @example | |
| * // returns '/' | |
| * toRoute('/'); | |
| */ | |
| export function toRoute(pathname: string): string { | |
| return pathname.replace(/(?:\/index)?\/?$/, '') || '/' | |
| } | |