Issue with Routing in Next.js Application Deployed on Cloudflare Pages

I have deployed a Next.js application on Cloudflare Pages which has /app route which is an SPA, and I’m facing an issue with routing. The application works fine when navigating between pages using client-side routing. However, when I refresh the page or try to directly access a route by entering the URL in the browser, I get a 404 error.

We tried to use URL redirects. Here is the content of my _redirects file:

/app/*  /app/[[...all]]/index.html  200
/*      /index.html      200

We also url re-write. both didn’t work.

I have tried different configurations and none of them seem to solve the issue. I’m wondering if there’s something I’m missing or if this is a limitation or configuration issue with Cloudflare Pages.

Any help or guidance would be greatly appreciated.