Next.js Discord

Discord Forum

useRouter()

Answered
TK-ed posted this in #help-forum
Open in Discord
Im trying to pass a value as query in router but it comes undefined
Answered by Ray
export default function Success({ searchParams }) {
  const email = searchParams.email
}

the page receive a searchParams object in app router
https://nextjs.org/docs/app/api-reference/file-conventions/page
View full answer

9 Replies

@TK-ed Im trying to pass a value as query in router but it comes undefined
export default function Success({ searchParams }) {
  const email = searchParams.email
}

the page receive a searchParams object in app router
https://nextjs.org/docs/app/api-reference/file-conventions/page
Answer
export default function Success({ searchParams }) {
  const email = searchParams
}


thanks it worked
 try {
      e.preventDefault();
      console.log(user);
      const response = await axios.post("/api/login", user);
      if(response.status==200)
        router.push(`/success?email=${user.email}`);
      setUser({ email: "", password: "" });
    } catch (error) {
      console.log("Signup failed", error.message);
    }
  };


so i want to push my page only if the login is successfull but it does tht no matter what, i tried giving status code but it didnt work either
nope
even if the statuscode isnt 200 it works lol
@TK-ed even if the statuscode isnt 200 it works lol
 if(response.data.status==200)

this I think?
lemme try
works thank you pro