The easiest solution is to use Bulk Redirects. You can setup bulk redirects and add a redirect from your pages.dev zone to your real domain very easily in the Cloudflare dashboard.
Or you could do something like this in your _headers:
This instructs search engines that the real URL is somewhere else (via canonical), not to index the current page, and then uses the Refresh header to instruct clients to redirect after 5 seconds to a new URL.
Do note however that Refresh isn’t actually part of the HTTP standard, but is supported in all common browsers. I’d probably do a combination of all of the above, plus your client-side script, if you were to use this option.
And finally another alternative would be to use a Pages Function specifically and return a 301 response when request.url matches pages.dev.