Download next.js/packages/next/src/shared/lib/router/utils/get-route-from-asset-path.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 643 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/shared/lib/router/utils/get-route-from-asset-path.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/shared/lib/router/utils/get-route-from-asset-path.ts
-
curl -L -o get-route-from-asset-path.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/shared/lib/router/utils/get-route-from-asset-path.ts
643 Bytes
| // Translate a pages asset path (relative from a common prefix) back into its logical route | |
| import { isDynamicRoute } from './is-dynamic' | |
| // "asset path" being its javascript file, data file, prerendered html,... | |
| export default function getRouteFromAssetPath( | |
| assetPath: string, | |
| ext: string = '' | |
| ): string { | |
| assetPath = assetPath.replace(/\\/g, '/') | |
| assetPath = | |
| ext && assetPath.endsWith(ext) ? assetPath.slice(0, -ext.length) : assetPath | |
| if (assetPath.startsWith('/index/') && !isDynamicRoute(assetPath)) { | |
| assetPath = assetPath.slice(6) | |
| } else if (assetPath === '/index') { | |
| assetPath = '/' | |
| } | |
| return assetPath | |
| } | |