Skip to content

Commit

Permalink
Platform redirect with hash (#10142)
Browse files Browse the repository at this point in the history
* return 404 if no platform applies on platform-redirect

* fix: account for url encoded #hash in `next` url on platform-redirect
  • Loading branch information
a-hariti authored and matejminar committed Jun 6, 2024
1 parent 262062c commit 2677410
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/platform-redirect/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {redirect} from 'next/navigation';
import {notFound, redirect} from 'next/navigation';

import {DocPage} from 'sentry-docs/components/docPage';
import {PlatformIcon} from 'sentry-docs/components/platformIcon';
Expand All @@ -14,16 +14,22 @@ export default async function Page({
if (Array.isArray(next)) {
next = next[0];
}
// discard the hash
const [pathname, _] = next.split('#');
const rootNode = await getDocsRootNode();
// get rid of irrelevant platforms for the `next` path
const platformList = extractPlatforms(rootNode).filter(platform_ => {
return !!nodeForPath(rootNode, [
'platforms',
platform_.key,
...next.split('/').filter(Boolean),
...pathname.split('/').filter(Boolean),
]);
});

if (platformList.length === 0) {
return notFound();
}

const requestedPlatform = Array.isArray(platform) ? platform[0] : platform;
if (requestedPlatform) {
const isValidPlatform = platformList.some(
Expand Down

0 comments on commit 2677410

Please sign in to comment.