#Getting next router was not mounted error
1 messages · Page 1 of 1 (latest)
Hi @warm thistle. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Based on the knowledge sources provided, it seems like you're encountering an error because you're using the useRouter hook from next/router in the app directory. In the app directory, you should use the new hooks imported from next/navigation instead of next/router.
Here's how you can modify your code:
import { useRouter, usePathname, useSearchParams } from 'next/navigation'
const ResultPage = () => {
const { user } = useUser();
const router = useRouter();
const pathname = usePathname();
const searchParams = useSearchParams();
// ...
}
In this code, useRouter is imported from next/navigation, and the pathname and query are obtained from the usePathname and useSearchParams hooks, respectively.
Please note that these new hooks are only supported in Client Components and cannot be used in Server Components.