Direct /pages not accessible in Workers

We have recently started trying cloudflare workers and deployed react app build with next.js

We we are trying to access /pages-name directly then system prompts 404
But when website is deployed in netlify with (_redirects) file with following:

/* /index.html 200

then it allows us to redirect pages directly. But, it does not work in cloud flare worker.
404 Error example page:

Look forward to community’s guidance/assistance in solving problem.

Just to be clear, are you using Pages or Workers here?

Pages supports SPAs out of the bat, on a not found page it will first look for a 404.html and if that isn’t found then serve index.html

So, as long as you don’t have a 404.html, your index.html will always be served.

1 Like

@Walshy : Thank you for proactive reply. We are using Workers here and facing problem on same. - Main site - Not working

name = “xxxxx”
type = “webpack”
account_id = “xxxxxx”
workers_dev = true
route = “”
zone_id = “”

bucket = “./out”
entry-point = “workers-site”

from = “/*”
to = “/”
status = 200

Details within wrangler.toml file

Ok, so Workers do not respect any file like _redirects, _headers, etc. These are specific to Pages.

You would need to add that part in yourself. I’m assuming you’re using Workers Sites so kv-asset-handler. There’s a serveSinglePageApp available to you there - GitHub - cloudflare/kv-asset-handler: Routes requests to KV assets

I am not the most experienced with kv-asset-handler so if you need more help, joining the Discord would be your best bet. Invite: Cloudflare Workers

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.