Skip to content

Commit

Permalink
Merge pull request pheralb#241 from ticua07/add-error-404-handling
Browse files Browse the repository at this point in the history
Handle non-existant categories and urls
  • Loading branch information
pheralb committed Feb 3, 2024
2 parents 04922c5 + 3608829 commit 72ff8b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/routes/+error.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script lang="ts">
import { redirect } from '@sveltejs/kit';
redirect(301, '/');
</script>
5 changes: 5 additions & 0 deletions src/routes/directory/[slug]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export const load = (async ({ params }) => {
}
});

// If SVGs array is empty, category can't exist
if (svgsByCategory.length === 0) {
return error(404, 'Not found');
}

return {
category: slug as string,
svgs: svgsByCategory
Expand Down

0 comments on commit 72ff8b2

Please sign in to comment.