Skip to content

Commit

Permalink
Add 404s for invalid refs
Browse files Browse the repository at this point in the history
  • Loading branch information
brookslybrand committed Feb 10, 2025
1 parent fff80e0 commit 91fbeb0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions _redirects
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
/reference /en/main/reference

# removed `/docs` prefix
/docs /home
/docs/en/v6/* /en/v6.3.0/*
/docs/* /*

Expand Down
13 changes: 10 additions & 3 deletions app/pages/docs-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ export let loader = async ({ request, params }: Route.LoaderArgs) => {
}

// the /:ref param should only be used for v6 docs
// if ref is not a v6 ref, redirect to the /home of that ref
if (params.ref && !url.pathname.match(/^\/?(6)/)) {
throw redirect(url.pathname + "home");
if (params.ref) {
// if the ref is not a valid semver, this is 404
if (!semver.valid(params.ref)) {
throw new Response("Not Found", { status: 404 });
}

// if ref is not a v6 ref, redirect to the /home of that ref
if (!url.pathname.match(/^\/?(6)/)) {
throw redirect(url.pathname + "home");
}
}

let splat = params["*"];
Expand Down

0 comments on commit 91fbeb0

Please sign in to comment.