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

Fix i18n routing #397

Merged
merged 1 commit into from
Sep 18, 2021
Merged

Fix i18n routing #397

merged 1 commit into from
Sep 18, 2021

Conversation

calmery
Copy link
Contributor

@calmery calmery commented Sep 17, 2021

I changed my code according to the "I18N routing" in the official documentation, but it did not work correctly.

$ deno --version
deno 1.14.0 (release, x86_64-apple-darwin)
v8 9.4.146.15
typescript 4.4.2

$ aleph --version
aleph.js 0.3.0-beta.14
deno 1.14.0
v8 9.4.146.15
typescript 4.4.2

Maybe this bug is caused by a change made in 16483f9. In this commit, this code also needed to be changed.

Check the problem by using v0.3.0-beta.14 and making the following changes.

// ./examples/hello-world/aleph.config.ts
import type { Config } from "aleph/types.d.ts";

export default <Config> {
  i18n: {
    defaultLocale: "ja",
    locales: ["en", "ja"],
  },
};
// ./examples/hello-world/app.tsx
import { useRouter } from "aleph/react";

...

const { defaultLocale, locales } = useRouter();

// Before: defaultLocale=ja locales=[]
// After: defaultLocale=ja locales=["en","ja"]
console.log(
  `defaultLocale=${defaultLocale}`,
  `locales=${JSON.stringify(locales)}`,
);

...

return (

  ...

  <a href="/en">en</a> {/* 404 */}
  <a href="/">ja</a>

  ...

);

Regardless of the ssr option, the final rendering result will be as follows.

Before (e47d1ed) After (https://github.com/calmery/aleph.js/commit/3e25d5d98ea30155e34d95b0f788d91d66059e46)
Before After

After the fix, I have confirmed that i18n routing works correctly with the following command.

$ ALEPH_DEV=true deno run -A --unstable --location=http://localhost cli.ts dev ./examples/hello-world -L debug

@calmery calmery requested a review from ije as a code owner September 17, 2021 16:37
@ije
Copy link
Member

ije commented Sep 18, 2021

looks great, please change the line i commented before i merge. thanks @calmery

@ije
Copy link
Member

ije commented Sep 18, 2021

i am going to merge this pr, and will update the RouterOptions later, thanks @calmery

@ije ije merged commit 49cad1b into alephjs:master Sep 18, 2021
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

Successfully merging this pull request may close these issues.

2 participants