mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
fix same page type navigation
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { useRouter } from 'next/router';
|
||||
import React from 'react';
|
||||
|
||||
@@ -11,8 +12,8 @@ import { EventTypes } from './utils';
|
||||
|
||||
export default function useLogPageView(isInited: boolean) {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
const pathname = router.pathname;
|
||||
const tab = getQueryParamString(router.query.tab);
|
||||
const page = getQueryParamString(router.query.page);
|
||||
|
||||
@@ -22,9 +23,14 @@ export default function useLogPageView(isInited: boolean) {
|
||||
}
|
||||
|
||||
logEvent(EventTypes.PAGE_VIEW, {
|
||||
'Page type': getPageType(pathname),
|
||||
'Page type': getPageType(router.pathname),
|
||||
Tab: getTabName(tab),
|
||||
Page: page || undefined,
|
||||
});
|
||||
// these are only deps that should trigger the effect
|
||||
// in some scenarios page type is not changing (e.g navigation from one address page to another),
|
||||
// but we still want to log page view
|
||||
// so we use pathname from 'next/navigation' instead of router.pathname from 'next/router' as deps
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [ isInited, page, pathname, tab ]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user