We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f4d019e commit cadfedcCopy full SHA for cadfedc
resources/js/hooks/use-current-url.ts
@@ -28,7 +28,12 @@ export type UseCurrentUrlReturn = {
28
29
export function useCurrentUrl(): UseCurrentUrlReturn {
30
const page = usePage();
31
- const currentUrlPath = new URL(page.url, window?.location.origin).pathname;
+ const currentUrlPath = new URL(
32
+ page.url,
33
+ typeof window !== 'undefined'
34
+ ? window.location.origin
35
+ : 'http://localhost',
36
+ ).pathname;
37
38
const isCurrentUrl: IsCurrentUrlFn = (
39
urlToCheck: NonNullable<InertiaLinkProps['href']>,
@@ -47,6 +52,7 @@ export function useCurrentUrl(): UseCurrentUrlReturn {
47
52
48
53
try {
49
54
const absoluteUrl = new URL(urlString);
55
+
50
56
return comparePath(absoluteUrl.pathname);
51
57
} catch {
58
return false;
0 commit comments