'router.push() is not working as expected NextJS
I am trying to redirect the user to the search results, but router.push() is not working apparently. I changed url to page that don't exist and the route changes, but when it comes to using the url of page already created, nothing happens.
I tried doing something like this, but it's not working either.
import { useRouter } from 'next/router';
const router = useRouter();
const search = () => {
router.push('/search');
};
}
Solution 1:[1]
The solution here is to prevent default function by doing something like this:
import { useRouter } from 'next/router';
const router = useRouter();
const Search = (e) => {
e.preventDefault()
router.push("/search");
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Thamagik |
