-
-
Notifications
You must be signed in to change notification settings - Fork 883
Open
Labels
enhancementNew feature or request.New feature or request.
Description
What is the feature you are proposing?
Redirects are essential for SSG to ensure users and search engines are properly directed when URLs change. This supports smooth migrations, maintains SEO value, and prevents broken links.
Feature Idea
When an endpoint that performs a redirect is defined as follows:
import { Hono } from 'hono'
import { toSSG } from 'hono/ssg'
import fs from 'fs/promises'
const app = new Hono()
app.get("/old", (c) => {
return c.redirect("/new")
})
app.get("/new", (c) => {
return c.render(
<>
<title>New Page</title>
<meta name='description' content='This is the new page.' />
new page content.
</>
)
})
toSSG(app, fs)
export default appold.html is generated as follows:
<!DOCTYPE html>
<title>Redirecting to: /new</title>
<meta http-equiv="refresh" content="0;url=/new" />
<meta name="robots" content="noindex" />
<link rel="canonical" href="/new" />
<body>
<a href="/new">Redirecting from <code>/old</code> to <code>/new</code></a>
</body>Alternatively, an option can be added to ToSSGOptions in toSSG to define a mapping for redirects. This is inspired by Astro1.
export interface ToSSGOptions {
dir?: string;
beforeRequestHook?: BeforeRequestHook | BeforeRequestHook[];
afterResponseHook?: AfterResponseHook | AfterResponseHook[];
afterGenerateHook?: AfterGenerateHook | AfterGenerateHook[];
concurrency?: number;
extensionMap?: Record<string, string>;
plugins?: SSGPlugin[];
redirects?: Record<string, string>; // 👈
}Footnotes
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request.New feature or request.