T
TanStack2w ago
rare-sapphire

Does onResolved fire on initial page load in TanStack Router?”

Hi, I have a question about router.subscribe in combination with the default browser routing (createRouter). If I subscribe like this:
router.subscribe('onResolved', (evt) => {
if (evt.pathChanged) {
trackPageView(evt.toLocation.pathname);
}
});
router.subscribe('onResolved', (evt) => {
if (evt.pathChanged) {
trackPageView(evt.toLocation.pathname);
}
});
Will the onResolved event also fire on the first page load (browser reload / direct hit)? I’m trying to determine if this alone is enough for tracking page views with Mixpanel, or if I also need something like this in __root to catch the initial view:
const pathname = useLocation({ select: (l) => l.pathname });
useEffect(() => {
trackPageView(pathname);
}, []);
const pathname = useLocation({ select: (l) => l.pathname });
useEffect(() => {
trackPageView(pathname);
}, []);
Thanks in advance for clarifying!
1 Reply
liable-blush
liable-blush2w ago
yes it should be fire also on initial page load. is that not working?

Did you find this page helpful?