Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with base path set in a config #21

Closed
dallyh opened this issue Sep 2, 2023 · 5 comments
Closed

Usage with base path set in a config #21

dallyh opened this issue Sep 2, 2023 · 5 comments

Comments

@dallyh
Copy link

dallyh commented Sep 2, 2023

I cannot get my head around on how to use this integration with base path. Everything works fine when the base path is not set, that is when the page is located for ex. under http://localhost:4321/projects/, but with base path, no locales get resolved and return 404 - for ex. http://localhost:4321/website-concept/en/projects/.

image

My config for locales is set like this:

import { defineConfig } from "astro/config";
import { i18n } from "astro-i18n-aut/integration";
import react from "@astrojs/react";

const defaultLocale = "cs";
const locales = {
    en: "en-US", 
    cs: "cs-CZ",
};

// https://astro.build/config
export default defineConfig({
    site: "https://some-website.com",
    base: "/website-concept",
    trailingSlash: "always",
    integrations: [
        react(),
        i18n({
            locales,
            defaultLocale,
        }),
    ],
});

Thanks for any help with this!

@dallyh dallyh changed the title Useage with base path set in a config Usage with base path set in a config Sep 2, 2023
@jlarmstrongiv
Copy link
Owner

jlarmstrongiv commented Sep 2, 2023

@dallyh do you have a github repo I could look at?

I’d like to see whether this is part of a known Astro v3 bug #19 (I’m thinking it is) or something else.

If is related to #19, the good news is that it’s only a problem with the dev command. The build and preview still work.

I wrote support for base paths, but there may be a bug in the implementation, so it could always be something else too.

@dallyh
Copy link
Author

dallyh commented Sep 2, 2023

@jlarmstrongiv I've just created one here: https://github.com/dallyh/astro-i18n-base-path

The issue seems to persists even on build, as when I build it with base path set and then run preview, the localized pages always return 404.

@seanpue
Copy link

seanpue commented Sep 2, 2023

In the demo uploaded, the base path is being duplicated, so this works: http://localhost:4321/example-base/example-base/es/. It appears config.base is not necessary here.

@jlarmstrongiv
Copy link
Owner

Thank you @dallyh and @seanpue!

@seanpue you are right, Astro automatically adds config.base

@dallyh thank you for the reproduction! I have fixed the paths in 0.3.5 and have added baseUrl support to all helper functions too

Please let me know if either of you run into any more issues with base!

@jlarmstrongiv
Copy link
Owner

@seanpue and @dallyh

I realized that some functions like middleware didn’t support BASE_URL. the latest version 0.4.14 should have fixed it for all functions.

This major upgrade also renamed some helper functions and removed all params from middleware. I can now import the defaultLocale and BASE_URL into helper functions and middleware with the new virtual modules implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants