mirror of https://github.com/sunface/rust-course
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
499 B
21 lines
499 B
|
5 years ago
|
import { useRouter } from "next/router"
|
||
|
|
import { useEffect } from "react"
|
||
|
|
|
||
|
|
const useRouteChanged = (fn: () => void) => {
|
||
|
|
const router = useRouter()
|
||
|
|
useEffect(() => {
|
||
|
|
const handleRouteChange = (url: string) => {
|
||
|
|
fn()
|
||
|
|
console.log("App is changing to: ", url)
|
||
|
|
}
|
||
|
|
|
||
|
|
router.events.on("routeChangeComplete", handleRouteChange)
|
||
|
|
|
||
|
|
return () => {
|
||
|
|
router.events.off("routeChangeComplete", handleRouteChange)
|
||
|
|
}
|
||
|
|
}, [router.events, fn])
|
||
|
|
}
|
||
|
|
|
||
|
|
export default useRouteChanged
|