Some help figuring out why +page.server.js load functions are not firing

I recently decided to localize my site using the sveltekit-i18n library, following this example. The problem is that in it the handle hook seems to mess with the load functions when redirecting using the default locale.

This is my version of the handle hook:

// hooks.server.js
import { defaultLocale, loadTranslations, locales } from '$lib/translations';
import { redirect } from '@sveltejs/kit';

const routeRegex = new RegExp(/^/[^.]*([?#].*)?$/);

/** @type {import('@sveltejs/kit').Handle} */
export const handle = async ({ event, resolve }) => {
    const { url, request, isDataRequest } = event;
    const { pathname, origin } = url;

    // If this request is a route request
    if (routeRegex.test(pathname)) {
        // Get defined locales
        const supportedLocales = locales.get().map((l) => l.toLowerCase());

        // Try to get locale from `pathname`.
        let locale = supportedLocales.find(
            (l) => l === `${pathname.match(/[^/]+?(?=/|$)/)}`.toLowerCase()
        );

        // We want to redirect the default locale to "no-locale" path
        if (locale === defaultLocale && !request.headers.get('prevent-redirect')) {
            const localeRegex = new RegExp(`^/${locale}`);
            const location = `${pathname}`.replace(localeRegex, '') || '/';

            return new Response(undefined, { headers: { location }, status: 301 });

            // If route locale is not supported
        } else if (!locale) {
            // Get user preferred locale if it's a direct navigation
            // if (!isDataRequest) {
            //  locale =
            //      `${`${request.headers.get('accept-language')}`.match(/[a-zA-Z]+?(?=-|_|,|;)/)}`.toLowerCase();
            // }

            // Get user preferred locale if it's a direct navigation
            if (!isDataRequest) {
                locale = event.cookies.get('locale');
            }

            // Set default locale if user preferred locale does not match
            if (!supportedLocales.includes(locale)) locale = defaultLocale;

            if (locale === defaultLocale) {
                const path = `${pathname}`.replace(//$/, '');
                const redirectTo = `${origin}/${locale}${path}${isDataRequest ? '/__data.json?x-sveltekit-invalidated=100' : ''}`;

                // We want to prevent redirect to fetch data for the default locale
                request.headers.set('prevent-redirect', '1');

                // Fetch the redirected route
                const response = await fetch(redirectTo, request);

                // Get response body and set html headers
                const data = await response.text();

                // Serve the redirected route.
                // In this case we don't have to set the html 'lang' attribute
                // as the default locale is already included in our app.html.
                return new Response(data, {
                    ...response,
                    headers: {
                        ...response.headers,
                        'Content-Type': isDataRequest ? 'application/json' : 'text/html'
                    }
                });
            }

            // 301 redirect

            return new Response(undefined, {
                headers: { location: `/${locale}${pathname}` },
                status: 301
            });
        }

        // Add html `lang` attribute
        return resolve(
            { ...event, locals: { lang: locale } },
            {
                transformPageChunk: ({ html }) => html.replace('%lang%', `${locale}`)
            }
        );
    }

    return resolve(event);
};

// /** @type {import('@sveltejs/kit').HandleServerError} */
// export const handleError = async ({ event }) => {
//  const { locals } = event;
//  const { lang } = locals;

//  await loadTranslations(lang, 'error');

//  console.log(event);

//  return locals;
// };

There are three locales en, bg, and pl. The idea is however when navigating using the defaultLocale (bg) to remove it from the URL. For example somesite.eu/bg/services becomes somesite.eu/services. And it works as expected, but when navigating to a page that is dependent on data provided by a load function it just won’t trigger the load function. This behavior is only present when navigating using the defaultLocale. Or in other words only when the handle hook tries to redirect to a non-localized URL. For example, navigation to somesite.eu/services won’t trigger the +page.server.js load function, but somesite.eu/en/services will.

For this reason, this is the route structure that the example suggests:

.
└── src/
    ├── routes/
    │   └── [...lang=locale]/
    │       ├── route1/
    │       │   ├── +page.svelte
    │       │   └── +page.server.js
    │       ├── route2/
    │       │   ├── +page.svelte
    │       │   └── +page.server.js
    │       ├── route3/
    │       │   ├── +page.svelte
    │       │   └── +page.server.js
    │       ├── +layout.js
    │       ├── +layout.server.js
    │       └── +error.svelte
    ├── app.html
    └── +hooks.server.js
// params/locale.js
import { locales } from '$lib/translations';

/** @type {import('@sveltejs/kit').ParamMatcher} */
export function match(param) {
    const definedLocales = locales.get();
    const paths = [...definedLocales, ''];
    const slashPaths = paths.map((l) => `${l}/`);

    return [...paths, ...slashPaths].includes(param);
}

I tried to debug the problem but my understanding of sveltekit’s data loading is not on that level.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật