Skip to content

Avoid 404 for pages without props handler (fix #66)#67

Merged
frandiox merged 3 commits intomasterfrom
issue-66
Nov 6, 2021
Merged

Avoid 404 for pages without props handler (fix #66)#67
frandiox merged 3 commits intomasterfrom
issue-66

Conversation

@m3hari
Copy link
Collaborator

@m3hari m3hari commented Oct 29, 2021

As stated in the title closes #66

@m3hari m3hari requested a review from frandiox October 29, 2021 04:17
@m3hari
Copy link
Collaborator Author

m3hari commented Oct 29, 2021

There is a slightly related issue, that is beyond scope of this PR.

Currently in ssr mode server always returns 200 status even for not found pages, but it might be nice to return a 404 status code for those pages for semantics.
I think to do that the renderer (vite-ssr) should return status code, For vue we can do something like this
after this line

const route = router.currentRoute.value 
const statusCode = route.fullPath === '/' || route.matched.length > 0 ? 200 : 404

@frandiox
Copy link
Owner

@m3hari Thanks! I think, however, this would break some use cases like throwing errors or returning statuses from the props handler: #60

What we want to do is remove the default-to-404 only when there is no props handler during rendering, which is happening here. We could start returning undefined instead (keep the options) if there is no handler. Then, update handlePropsRequest to return 404 if the response is undefined and also handleViewRendering to default to empty object so it uses the rendering status instead 🤔

That should make it work for your use-case and also keep it working when a proper status code is returned from the props handler.

@m3hari
Copy link
Collaborator Author

m3hari commented Nov 3, 2021

@frandiox Updated accordingly thanks for the guidance.

@frandiox
Copy link
Owner

frandiox commented Nov 6, 2021

@m3hari I've made a small fix and I think we can release it now. Thanks!

@frandiox frandiox merged commit cbcc77d into master Nov 6, 2021
@frandiox frandiox deleted the issue-66 branch November 6, 2021 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Routes with no props handler returning 404 status

2 participants