I'm using the latest version of Next.js (13.4) with the new app router.
In my application, I have a Link component with a button inside a ../components/products.tsx file.
Each product has a "details" button that navigates to a dynamic route using the Link component. I'm passing query parameters along with the route using the pathname and query properties of the Link component.
Here's an example of the Link component in the ../components/products.tsx file:
<Link href={{
pathname:`product/${item._id}`,
query:{
_id: item._id,
title: item.title,
description: item.description,
oldPrice: item.oldPrice,
price: item.price,
brand: item.brand,
image: item.image,
isNew: item.isNew,
category: item.category,
},
}}
as ={`product/${item._id}`}
>
In the dynamic route component (page.tsx) with the path app/product/[id], I want to access the query parameters and render them on the page. Here's an example of the page.tsx file:
import React from 'react';
import { useRouter } from 'next/router';
const ProductPage = () => {
const router = useRouter();
const query = router.query;
return (
<div>
<h1>Product Details</h1>
<p>ID: {query._id}</p>
<p>Title: {query.title}</p>
<p>Description: {query.description}</p>
<p>Old Price: {query.oldPrice}</p>
<p>Price: {query.price}</p>
<p>Brand: {query.brand}</p>
<p>Image: {query.image}</p>
<p>Is New: {query.isNew}</p>
<p>Category: {query.category}</p>
</div>
);
};
export default ProductPage;
The problem I'm facing is that router.query doesn't work with the new app router in Next.js 13.4.
I'm looking for a solution to access the query parameters in the new app router of Next.js 13.4. Any help or suggestions would be greatly appreciated. Thank you
I've tried using searchParams, useSearchParams, and usePathname, but I'm unable to retrieve the query parameters.