I have difficulties to understand how the next.js routing works and I think I'm using it wrong. When I navigate forward through the pages with Link, I have no problem, but when I use the browser back button it sometimes reload the previous page and sometimes stays on the same page whereas the url changed. Then I need to refresh the page manually
I guess this is something I do wrong, but can't figure out what
index.js :
import Head from "next/head";
import NewBooks from "../components/Homepage";
import { getProducts } from "../utils/api";
const HomePage = ({ products }) => {
return (
<div>
<Head>
<title>Classe moyenne éditions</title>
</Head>
<NewBooks products={products} />
</div>
);
};
export async function getStaticProps() {
const products = await getProducts();
return { props: { products } };
}
export default HomePage;
books/index.js :
import Head from "next/head";
import Catalogue from "../../components/Catalogue";
import { getProducts } from "../../utils/api";
const CataloguePage = ({ products }) => {
return (
<div>
<Head>
<title>Catalogue</title>
</Head>
<Catalogue products={products} />
</div>
);
};
export async function getStaticProps() {
const products = await getProducts();
return { props: { products } };
}
export default CataloguePage;
component/Catalogue.js :
import Link from "next/link"; import { getStrapiMedia } from "../utils/medias"; import { Card } from 'react-bootstrap';
const Catalogue = ({ products }) => {
return ( <div className="container-cat"> {products.map((_product) => ( <Card id="lien" key={_product.id} alt="book" className="items"> <Link href='/books/[name]' as={`/books/${encodeURIComponent(_product.name)}`}> <a> <Card.Body> <Card.Img variant="top" src={getStrapiMedia(_product.grid_pic.url)} width="200px" /> <Card.Title>{_product.name}<br />{_product.author}<br />{_product.price} €</Card.Title> </Card.Body> </a> </Link> </Card> )) } </div> );
};
export default Catalogue;