这是indexloc提供的服务,不要输入任何密码
Skip to content

Dynamic blog post missing doesn't return 404 but returns under construction #757

@Romstar

Description

@Romstar

Describe the bug
Whenever you navigate to a route that a blog post doesn't exist, i.e. http://localhost:3000/blog/does-not-exist then you'll receive a 200 with an under construction page. It should return a 404 since it doesn't exist otherwise Google will continue to index the page.

Solution:
https://nextjs.org/docs/app/api-reference/functions/not-found

Simply import notFound from next/navigation and return that instead of the construction react component.

import { notFound } from 'next/navigation'
if (postIndex === -1) {
    return notFound()
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions