Skip to content

Instantly share code, notes, and snippets.

@chaance
chaance / root.tsx
Created March 11, 2023 00:32
Remove trailing slashes to URL via redirect in Remix
import { redirect, type LoaderArgs } from "@remix-run/node";
export async function removeTrailingSlashes(request: Request) {
let url = new URL(request.url);
if (url.pathname.endsWith("/") && url.pathname !== "/") {
throw redirect(url.pathname.slice(0, -1) + url.search);
}
}
export async function loader({ request }: LoaderArgs) {