'Can not add query params to the nextjs dynamic route

I have file named. [slug].js.

what I am trying to do is that I want to add query parameter to this dynamic route, this is the code.

   await router.replace({
          pathname: `${router.pathname}`,
          query: { coupon },
        },
        undefined,
        { shallow: true });

This works fine every static page but on dynamic page it gives me this error:

Error: The provided `href` (/home/[slug]?theme=dark) value is missing query values (slug) to be interpolated properly. Read more: https://err.sh/vercel/next.js/href-interpolation-failed

any suggestions please?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source