Download next.js/packages/next/src/shared/lib/router/utils/is-local-url.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 662 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/shared/lib/router/utils/is-local-url.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/shared/lib/router/utils/is-local-url.ts
-
curl -L -o is-local-url.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/shared/lib/router/utils/is-local-url.ts
662 Bytes
| import { isAbsoluteUrl, getLocationOrigin } from '../../utils' | |
| import { hasBasePath } from '../../../../client/has-base-path' | |
| /** | |
| * Detects whether a given url is routable by the Next.js router (browser only). | |
| */ | |
| export function isLocalURL(url: string): boolean { | |
| // prevent a hydration mismatch on href for url with anchor refs | |
| if (!isAbsoluteUrl(url)) return true | |
| try { | |
| // absolute urls can be local if they are on the same origin | |
| const locationOrigin = getLocationOrigin() | |
| const resolved = new URL(url, locationOrigin) | |
| return resolved.origin === locationOrigin && hasBasePath(resolved.pathname) | |
| } catch (_) { | |
| return false | |
| } | |
| } | |