Skip to content

Commit 1ff775e

Browse files
committed
Move regex to constant
1 parent 336242a commit 1ff775e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/remix-react/components.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,16 @@ function usePrefetchBehavior(
283283
];
284284
}
285285

286+
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
287+
286288
/**
287289
* A special kind of `<Link>` that knows whether or not it is "active".
288290
*
289291
* @see https://remix.run/components/nav-link
290292
*/
291293
let NavLink = React.forwardRef<HTMLAnchorElement, RemixNavLinkProps>(
292294
({ to, prefetch = "none", ...props }, forwardedRef) => {
293-
let isAbsolute =
294-
typeof to === "string" && /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(to);
295+
let isAbsolute = typeof to === "string" && ABSOLUTE_URL_REGEX.test(to);
295296

296297
let href = useHref(to);
297298
let [shouldPrefetch, prefetchHandlers] = usePrefetchBehavior(
@@ -324,8 +325,7 @@ export { NavLink };
324325
*/
325326
let Link = React.forwardRef<HTMLAnchorElement, RemixLinkProps>(
326327
({ to, prefetch = "none", ...props }, forwardedRef) => {
327-
let isAbsolute =
328-
typeof to === "string" && /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(to);
328+
let isAbsolute = typeof to === "string" && ABSOLUTE_URL_REGEX.test(to);
329329

330330
let href = useHref(to);
331331
let [shouldPrefetch, prefetchHandlers] = usePrefetchBehavior(

0 commit comments

Comments
 (0)