Is it safe to manually set abortStatusCode
?
#1492
Unanswered
develohpanda
asked this question in
Help & Questions
Replies: 1 comment 5 replies
-
As you probably already figued out, the usual way is to define a Alternatively to what you're currently doing, a potentially clearer way would be to set a custom property I'm curious: why do you want to use React Router? |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hiya!
The only way I can find to alter the returned HTTP Status Code, and have the Vike logs also reflect the code, is to set
pageContext.abortStatusCode
manually. I have an integration with React Router 5 (not a deep integration viaonBeforeRender
), which appears to work as intended. I am adapting their documentation for server rendering, specifically for updating the status code.In their example, they access a context object on the
StaticRouter
like so:I have adapted this to be
In my express server, I can do something like
res.status(staticContext.status || httpResponse.statusCode)
, which also works correctly however vike logs won't reflect that.Is there a different way to override the status code in Vike-land, other than using
throw render(404)
?Beta Was this translation helpful? Give feedback.
All reactions