â This might change a bit with SvelteKit 1.0 â
A sveltkit hook that makes redirects easy đ
/about
=> /about-new
)/blog
=> https://blog.my-fancy.page
)MovedPermanently = 301
)/products/{id}
=> /products-new/{id}/details
)import { RedirectHook, type StringRedirects } from "@svackages/sveltkit-hook-redirect";
import type { Handle } from "@sveltejs/kit";
const redirects: StringRedirects = {
'/about': {
to: '/about-new',
code: 301,
},
'/temporary-redirect': {
to: '/',
},
}
export const handle: Handle = ({ event, resolve }) => RedirectHook({ event, resolve, redirects });
import { StringRedirects } from "@svackages/sveltkit-hook-redirect";
/** @type {import(@svackages/sveltkit-hook-redirect).StringRedirects} */
const redirects = {
'/about': {
to: '/about-new',
code: 301,
},
'/temporary-redirect': {
to: '/',
},
}
/** @type {import('@sveltejs/kit').Handle} */
export const handle = ({ event, resolve }) => RedirectHook({ event, resolve, redirects });
import { RedirectHook, type StringRedirects } from "@svackages/sveltkit-hook-redirect";
import type { Handle } from "@sveltejs/kit";
const matchers: RegexRedirect[] = [
{
fromMatcher: /^\/products\/(\d+)$/,
to: '/products-new/$1',
replace: true,
},
{
fromMatcher: /^\/blog.*/,
to: 'https://dev.to/dreitzner',
code: 307,
},
]
export const handle: Handle = ({ event, resolve }) => RedirectHook({ event, resolve, matchers });
import { RedirectHook } from "@svackages/sveltkit-hook-redirect";
/** @type {import(@svackages/sveltkit-hook-redirect).RegexRedirect[]} */
const matchers = [
{
fromMatcher: /^\/products\/(\d+)$/,
to: '/products-new/$1',
replace: true,
},
{
fromMatcher: /^\/blog.*/,
to: 'https://dev.to/dreitzner',
code: 307,
},
]
/** @type {import('@sveltejs/kit').Handle} */
export const handle = ({ event, resolve }) => RedirectHook({ event, resolve, matchers });