I am building a simple app using nextjs. most of my components are functional components. However, I have a class component to handle form.
I want to redirect to the home page after the form is submitted. console.log(this.router) gives undefined. Since it is a class component I can't use useRouter() hook. How do I get reference to router in class components in next.js?
console.log(this.router)
useRouter()
Finally I got the answer,
import Router from 'next/router'
and use Router.push(...)
Router.push(...)
1.4m articles
1.4m replys
5 comments
57.0k users