Allow route for fetch only, not as public-facing browser url?


trying to separate my overall problem (Holding page for CPT including posts of that CPT (eg /events)) into separate issues

I want to fetch content via eg fetch("/events-page") so I can insert that page’s content into another page (specifically my events archive), but I don’t want the user to be able to access directly

if I add a handler to 404 the pattern /events-page/, then it also stops the fetch from working

thanks for any advice

example here using

in this case I want to disable the /about-us url but still be able to fetch data from that page in the backend (which you can see on the Destinations and Movies archive pages, I pull in the excerpt from about-us)

If you enable the aboutUsHandler at the bottom of the theme index.js, then it breaks these because 404’ing the main page also disables the fetch routes

I solved like this

beforeSSR: async ({ state, actions, libraries }) => {
  if( === '/events-page/') {

    // manually 404 this route, ie when visiting
    Object.assign([], {
      isError: true,
      is404: true,
      isPostType: false,
      errorStatus: 404
  // fetch route still works
  if('/events/')) {
    // grab the content from our dummy page
    await actions.source.fetch("/events-page/")
1 Like