Skip to content

Commit

Permalink
Route redirects (#317)
Browse files Browse the repository at this point in the history
* Catch all route

* Extension redirect

* Clean up deprecations
  • Loading branch information
mersocarlin authored May 4, 2024
1 parent ecd31b8 commit 96f3cae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useRef } from 'react'
import type {
DataFunctionArgs,
LinksFunction,
LoaderFunctionArgs,
MetaFunction,
} from '@remix-run/node'
import {
Expand Down Expand Up @@ -91,7 +91,7 @@ export const meta: MetaFunction = () => {
]
}

export async function loader({ request }: DataFunctionArgs) {
export async function loader({ request }: LoaderFunctionArgs) {
const themeSession = await getThemeSession(request)

return {
Expand Down
6 changes: 6 additions & 0 deletions app/routes/$.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { redirect } from '@remix-run/node'
import type { LoaderFunctionArgs } from '@remix-run/node'

export async function loader({ params }: LoaderFunctionArgs) {
return redirect('/')
}
12 changes: 9 additions & 3 deletions app/routes/blog.$slug.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { json } from '@remix-run/node'
import type { DataFunctionArgs, MetaFunction } from '@remix-run/node'
import { json, redirect } from '@remix-run/node'
import type { LoaderFunctionArgs, MetaFunction } from '@remix-run/node'
import { useLoaderData } from '@remix-run/react'

import BlogPost from '~/components/BlogPost'
Expand All @@ -8,8 +8,14 @@ import PreviousBlogPosts from '~/components/PreviousBlogPosts'
import { getPostBySlug, getPreviousBlogPosts } from '~/utils/post.server'
import { getSocialMeta } from '~/utils/seo'

export async function loader({ params }: DataFunctionArgs) {
export async function loader({ params }: LoaderFunctionArgs) {
const currentSlug = params.slug || ''
// redirect urls as /blog/some-slug.md to /blog/some-slug
const [actualSlug, extension] = currentSlug.split('.')

if (extension) {
return redirect(`/blog/${actualSlug}`)
}

const [post, previousBlogPosts] = await Promise.all([
getPostBySlug(currentSlug),
Expand Down

0 comments on commit 96f3cae

Please sign in to comment.