Currently seeking a method to determine if the query value is empty using the path parameter approach. Have a file named pages/search/[variable1].js
Below is the code snippet:
import { useRouter } from "next/router"
const Variable= () => {
const router = useRouter()
const { variable1 } = router.query
console.log(variable1);
}
For instance, when accessing localhost:3000/search/abc
, 'abc' displays in the console. However, accessing it through localhost:3000/search/
does not show anything. What condition can I use to check if variable1
is empty? Tried using the ternary operator
variable1 ? console.log("not empty") : console.log("empty")
, but 'empty' does not appear in the console.