skip to Main Content

So, I want to create a dynamic route and pass the link to an external application under their callback section.
The URL is usually like this:

htttp://localhost3000/builder/live/thankyou?trxref={reference}

The reference is dynamic which means it changes and comes from the external website. I could do this easily in create react app. I am struggling with doing same in Nextjs.
Inside the page folder, I created mine this way:

builder/live/[slug].tsx

This is always returning page not found error whenever the urlgets hit. That is obviously because it is not the actual path. How do I achieve this since.
The entire idea is that a user pays for a product, after succeessfully paying, I want to redirect the user to this page in my Nextjs application and I need to create the page and pass that as a callback to the payment gateway website.

2

Answers


  1. Chosen as BEST ANSWER

    UPdate I made mistake with my api request which was causing the error. The error was not coming from Nextjs. I have corrected my mistake


  2. You can use this path:

    builder/live/thankyou.tsx

    and use this way to get the reference value:

    import { useRouter } from 'next/router';
    
    export default function Home() {
        const router = useRouter();
        const { reference } = router.query;
    
        return (
            <div>
                Thank you
            </div>
        )
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search