Next.js Discord

Discord Forum

router.asPath on Next.js 14 App Router

Unanswered
Brown bear posted this in #help-forum
Open in Discord
Brown bearOP
Hello!

I'm currently migrating my project from the pages router to the app router, and I have a useEffect which had router.asPath as a dependency back with next/router.

What's the migration for that using next/navigation?

Thank you!

Code Snippet:
const router = useRouter()
 const [messages, setMessages] = useState<MessageType[]>([]);
 const [loading, setLoading] = useState<boolean>(true);
 useEffect(() => {
    setMessages([]);
    setLoading(true);
 }, [router.asPath]);
 

1 Reply