Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

path.startsWith is not a function in next js

Why it is showing me path startsWith error. I'm trying to send the amount to the path

enter image description here

 import { useRouter } from 'next/navigation'

      const checkoutHandler = ()=>{
        router.push({
          pathname: '/checkout/[amount]',
          query: { amount: customAmount},
        })
      }


    <div className="continue-btn" onClick={()=> checkoutHandler()}>
       Continue
     </div>
like image 502
Sohaib Ashraf Avatar asked Oct 20 '25 03:10

Sohaib Ashraf


1 Answers

If you are using next/navigation you can't pass query params like this. Just use strings or template literals to add query params in next/navigation.

Check This URL : useRouter from next/navigation

Eg: In your code router.push(`/checkout/${[amount]}?amount=${customAmount}`)

N.B : I am not sure about your [amount] as you haven't mentioned whether it's from a dynamic route segment or something else.

like image 194
reasat Avatar answered Oct 23 '25 08:10

reasat