Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set 404 statusCode for current page? #2761

Closed
KonstantinVlasov opened this issue Feb 5, 2018 · 5 comments
Closed

How to set 404 statusCode for current page? #2761

KonstantinVlasov opened this issue Feb 5, 2018 · 5 comments
Labels

Comments

@KonstantinVlasov
Copy link

KonstantinVlasov commented Feb 5, 2018

Hi guys!

If some data not found, I want to stay on the current page (layout) but with 404 statusCode, without redirection. Is it possible?

This question is available on Nuxt.js community (#c2396)
@clarkdo
Copy link
Member

clarkdo commented Feb 5, 2018

Hi @KonstantinVlasov

What date do you mean? Can you describe your issue more specifically?

@KonstantinVlasov
Copy link
Author

Here our app: https://icons8.com/icon/set/abcdefg/all
In this page, I try to find 'abcdefg' icons. If no icons are found, I want to set 404 status for SEO, but I didn't want to redirect to the error page, so the user can continue using the app.

@clarkdo
Copy link
Member

clarkdo commented Feb 5, 2018

I suggest you asyncData or fetch to load the data, if abcdefg doesn't exist, you can set the statusCode:

// pages/icon/set/_search/all.vue
async asyncData({ res}) {
    const { data } = await axios.get('...')
    if (!data) {
        res.statusCode = 404
    }
}

@KonstantinVlasov
Copy link
Author

This is exactly what I needed, thanks!

@lock
Copy link

lock bot commented Nov 3, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 3, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants