-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic routing doesn't work. #32
Comments
I'm having issues with this too, except when using dynamic routing with the pages folder rather than app directory. Did you find a solution? |
Not yet. I think updated period of this repository is slow. |
Hey, I'm also using the appDir method and have this problem as well. I think I have narrowed it down to a missing header. A couple of technical notes I've gathered so far:
TL;DR: My hypothesis is that the problem does not lie in the @GregBrimble do you think this could be a plausible explanation? |
Update on the At first, I tried using CF Pages-like middlewares by creating a import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export const config = {
matcher: "/offers/:path*",
};
export function middleware(req: NextRequest) {
console.log("[middleware.ts] headers before:", req.headers);
req.headers.set("x-matched-path", "/offers/[id]");
console.log("[middleware.ts] headers after:", req.headers);
return NextResponse.next();
/**
* I also tried this:
*
const url = req.nextUrl.clone();
url.pathname = "/offers/[id]";
return NextResponse.rewrite(url);
*/
} Although the middleware runs (the headers are printed in In contrast, with ¹ Note that for this part of the experiment, I was using |
Another update: manually setting the I see the |
I was able to create a workaround for this problem. Not perfect, but it works: import { NextPageContext } from "next";
import { URLPattern } from "next/server";
export function parsePath(pathname: string, ctx: NextPageContext): any {
const pattern = new URLPattern({ pathname });
const result = pattern.exec(`http://host${ctx.req?.url}`);
return result?.pathname.groups || {};
} Then you can use this function in getServerSideProps: export async function getServerSideProps(ctx: NextPageContext) {
const { id } = parsePath('/post/:id', ctx);
const post = await fetch(`https://jsonplaceholder.typicode.com/posts/${id}`)
.then((response) => response.json());
return {
props: {
post,
}
}
} |
That's a great idea! |
Hello, I've been running into this as well and have come up with two solutions, 1 being the better option:
I've created a reproduction of this bug, along with the patched version of next-on-pages, proving 1. solution is viable. It's visible over here |
After doing some additional testing it appears my PR does not work 😭 ... I thought it was working as I was still using a patched version of next.js ... My 2nd approach still works, but I'd really like to not have to patch Next.js if it's avoidable. -- I've updated my reproduction case with data fetching (appDir / async function), along with the https://github.com/hanford/next-on-pages-32/tree/with-fetch |
Should this be closed? |
I am also having the same issue. On the development and on Firebase Hosting things are working fine. But on Cloudflare pages, I am getting 500 on the local environment and on production. I have made the root path dynamic. I have two files it seems that all the requests are going to the root path. |
How can I do this using the experimental app directory? |
Hi! I've been able to make your first solution work. It seems like the Request's headers are "immutable" so we need to copy the request before setting the I made a patch file (based on @hanford 's) for those who need a quick fix. I'm not sure why this issue is closed? It's still present in v0.3.0 |
I don't know why this is closed. I still have this issue: I have a dead simple setup but it's not working for dynamic pages: It returns
|
Hello, It sounds like your page might be getting statically generated to a HTML file at build time. That is actually a separate problem. At the moment, static HTML files are not handled properly - we need to rewrite URLs during the routing process, accounting for the rules in the config given to us in the Vercel build output. This would allow us to point the path towards the HTML file that the config tells us to use for that route, instead of relying on the outputted functions like we currently do. I believe this is why you are experiencing 404s at the moment. It is one of the things that #129 aims to resolve. If you are able to share a reproduction, that may be useful to confirm that this is the case. |
@james-elicx oh.. okay. Any workaround for the timebeing? |
Not really unless you want to change it to be SSR |
Not sure why this issue was closed? I don't see a reliable fix from the replies yet. Still getting this issue with NextJS 13.2.4 and dynamic routes in both the |
Hello @lenryk, this issue was to do with next-on-pages not handling dynamic parameters at all. While closed prematurely, the problem that this issue referred to was resolved. Your issue is most likely due to your project statically generating HTML files for the page at build time. You can see my explanation about that problem further above. This theory can be confirmed through your build logs if you would like to share them, or a reproduction. |
i am also facing same issues on my project app directory on local build it was loading dynamic page but on production it was throwing 404 not found how to fix this issue on other environment |
Hello @sanchitha-pof, can you please confirm that you are using the latest version of next-on-pages by checking the build log for your production deployment? Additionally, could you please share your deployment method; the Pages Git integration, or publishing with Wrangler? You'll see a little message at the start of the next-on-pages CLI that tells you the version it is currently using.
If you are using the latest version and this issue is still occuring, would you be able to please provide more information about your dynamic routes and, if possible, a reproduction? |
Also me. It throws 404 in the [slug] segments. By the way, doesn't display images. As far as I see, no route works properly. Because the page refreshing when navigating pages. Actually I didn't change the app, just deployed. What causes this issue? @james-elicx 20:05:14.692 | devDependencies:
20:05:14.693 | + @cloudflare/next-on-pages 1.5.0
20:05:14.693 | + vercel 30.0.0 Solved: #428 (comment) |
just update new nextjs version |
why is this closed? experiencing the same issue today with the latest latest version. |
I'm still facing the same problem, is there any updates to solve this? |
@9oelM it's closed because this specific issue and its cause was resolved. @9oelM @icanq If you are running into problems, please open a new issue with information about what exactly you're doing and is going wrong, as well as including some sort of reproduction so your problem can be properly investigated. |
I have used the below solution, it applies for static generation approach: |
Stuck here too chief |
I got this today after disabling zaraz. Enabling it again would fix the issue. I am not sure why. Uptime robot was returning: Ongoing incident on www.merklemap.com/ HTTP(S) monitor for https://www.merklemap.com/ Root cause With
I was not able to reproduce using curl and the same request data. I ended up rollbacking my use of pages. |
When I set up dynamic routing and deploy it on cloudflare pages, page fails with 500 error.
my code:
The text was updated successfully, but these errors were encountered: