Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
¿Cómo redirigir a otra página usando la pulsación de tecla en nextjs?

Necesito redirigir a los usuarios usando onkeypress en nextjs.

Tengo una entrada de búsqueda donde los usuarios pueden escribir y luego presionar la tecla Intro para ir a la otra página.

Lo que he probado:

 const handler = (e) => { const ENTER = 13; if (e.keyCode === ENTER) // do a history.push("/news"); console.log("enter");

};

 <input onKeyPress={(e) => handler(e)} type="text" name="search" placeholder="Search by keywords" className="p-4 md:p-6 w-full py-2 md:py-4 border-2 text-lg md:text-2xl xl:text-3xl border-gray-400 outline-none filosofia_italic bg-white placeholder-gray-400" />

Apreciaría tu ayuda.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Esto está cubierto por la documentación :

imperativo

next/link debería poder cubrir la mayoría de sus necesidades de enrutamiento, pero también puede realizar navegaciones del lado del cliente sin él, eche un vistazo a la documentación de next/router.

El siguiente ejemplo muestra cómo hacer navegaciones de página básicas con useRouter:

 import { useRouter } from 'next/router' export default function ReadMore() { const router = useRouter() return ( <button onClick={() => router.push('/about')}> Click here to read more </button> ) }
about 4 years ago · Juan Pablo Isaza Report

0

Puede usar el useRouter desde el siguiente: https://nextjs.org/docs/api-reference/next/router

Intenta cambiar tu controlador a

 import {useRouter} from "next/router"; const Component = () => { const router = useRouter(); const handler = (e) => { ... router.push("/news"); } return ( <input onKeyPress={handler} type="text" name="search" placeholder="Search by keywords" className="p-4 md:p-6 w-full py-2 md:py-4 border-2 text-lg md:text-2xl xl:text-3xl border-gray-400 outline-none filosofia_italic bg-white placeholder-gray-400" /> ) }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!