i18n
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { error, redirect } from '@sveltejs/kit';
|
||||
|
||||
import { deLocalizeHref, localizeHref } from '$lib/paraglide/runtime';
|
||||
|
||||
import type { GeoLocation } from '$lib/stores/settings';
|
||||
|
||||
export const geoLocationNameToRoute = (name: string) => {
|
||||
@@ -117,10 +119,12 @@ export async function resolveLocationFromRoute({
|
||||
|
||||
// trailingSlash is 'always' (see routes/+layout.ts), so the router serves
|
||||
// every path with a trailing slash. Match that here or the equality check
|
||||
// never holds and the redirect loops forever.
|
||||
// never holds and the redirect loops forever. The comparison also has to
|
||||
// ignore the locale prefix the URL carries, while the redirect keeps it -
|
||||
// otherwise every localized URL would bounce back to English.
|
||||
const canonicalPath = `${routePrefix}${buildLocationRoute(location)}/`;
|
||||
if (event.url.pathname !== canonicalPath) {
|
||||
throw redirect(303, canonicalPath);
|
||||
if (deLocalizeHref(event.url.pathname) !== canonicalPath) {
|
||||
throw redirect(303, localizeHref(canonicalPath));
|
||||
}
|
||||
|
||||
return location;
|
||||
|
||||
Reference in New Issue
Block a user