svelte-routing
svelte-routing copied to clipboard
Trigger a function everytime a route changes
Hello, I am trying to figure out how to run an analytic function every time the route changes.
I did not find anything in the documentation for this. Is this not possible?
Hey there,
Maybe issue https://github.com/EmilTholin/svelte-routing/issues/41#issuecomment-778765725 could be useful.
I went a different direction:
history.pushState = new Proxy(history.pushState, {
apply (target, thisArg, argumentsList) {
// run function stuff here
Reflect.apply(target, thisArg, argumentsList)
}
})
This has been working very well.
useLocation hook is a better options
@krishnaTORQUE Do you have a code example with useLocation?I must have missed this in the docs?
@krishnaTORQUE Do you have a code example with
useLocation?I must have missed this in the docs?
https://github.com/EmilTholin/svelte-routing/issues/255#issuecomment-1687692609