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

Support redirectToDefaultLang in static mode? #77

Closed
justincy opened this issue Mar 12, 2020 · 13 comments
Closed

Support redirectToDefaultLang in static mode? #77

justincy opened this issue Mar 12, 2020 · 13 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@justincy
Copy link
Contributor

It seems like we could support redirectToDefaultLang in static mode by using a catch-all route at the top level. That page could detect the language and perform the redirect accordingly.

@justincy
Copy link
Contributor Author

Here's an example of what I mean, as borrowed from the README:

├── ca
│   ├── about.js
│   ├── index.js
│   └── nested
│       └── index.js
├── en
│   ├── about.js
│   ├── index.js
│   └── nested
│       └── index.js
├── es
│   ├── about.js
│   ├── index.js
│   └── nested
│       └── index.js
└── [...path].js

@aralroca
Copy link
Owner

aralroca commented Mar 13, 2020

@justincy thank you a lot for your proposal!! 🚀

With "redirects" in static mode, do you mean that the browser does these redirects, doesn't it? (Router.replace)

I guess that it will be interesting to add the new config prop redirectToDefaultLang for both (static mode and for a custom server middleware).

  • redirectToDefaultLang=false as default, for backwards compatibility.
  • redirectToDefaultLang=true (if en is the defaultLanguage)->
    • Static mode: It redirects on the browser level, routes as /some/route to /en/some/route.
    • Custom server middleware: It redirects with a status 301 on the server, routes as /some/route to /en/some/route.

I will investigate the catch-all route, I never used before! 😄

@aralroca aralroca self-assigned this Mar 13, 2020
@aralroca aralroca added the enhancement New feature or request label Mar 13, 2020
@aralroca aralroca added this to the 0.11.0 milestone Mar 13, 2020
@aralroca
Copy link
Owner

aralroca commented Mar 13, 2020

I remember than @BjoernRave did a similar proposal here: #51, and we decided at that moment to don't bring this responsibility to the lib. However, if that feature is commonly used and it doesn't increase a lot the size of the lib, we can rethink it in order to implement it.

@aralroca
Copy link
Owner

Maybe we can provide more than one redirect mode:

  • redirectMode:
    • 'none' (by default) - No redirects
    • 'browserLang' - Redirect to the lang of the browser when the language is not present on the URL. If the browser language is not a provided language, we redirect to defaultLanguage.
    • 'defaultLang' - Redirect directly to the defaultLanguage when the language is not present on the URL.

@justincy
Copy link
Contributor Author

Maybe we can provide more than one redirect mode:

  • redirectMode:

    • 'none' (by default) - No redirects
    • 'browserLang' - Redirect to the lang of the browser when the language is not present on the URL. If the browser language is not a provided language, we redirect to defaultLanguage.
    • 'defaultLang' - Redirect directly to the defaultLanguage when the language is not present on the URL.

That's a good idea. But if you don't want to bother with language detection, you could just leave the current functionality of redirecting to the default lang and add language detection later.

@aralroca
Copy link
Owner

aralroca commented Mar 13, 2020

Great!! 🎉 In order to finish this issue:

  • Add docs on README explain it how it works
  • Add tests if is possible

@aralroca
Copy link
Owner

@justincy I did a prerelease under 0.11.0-canary.1 with the support of redirectToDefaultLang in static mode.

@aralroca
Copy link
Owner

@justincy I realized that it works using some path, but when the path is just the homepage (localhost:3000), it displays a 404:

image

@justincy
Copy link
Contributor Author

Thanks. I'll look into that bug.

@aralroca
Copy link
Owner

@justincy I did a PR fixing some issues that I found (they are described in the PR). If you can take a look!

@justincy
Copy link
Contributor Author

Great!! 🎉 In order to finish this issue:

  • Add docs on README explain it how it works
  • Implement redirectToDefaultLang for no static mode (custom server with a middleware)
  • Add tests if is possible

Updating the README and adding tests makes sense to me. But the bit about custom server and middleware doesn't make sense to me. Doesn't it already exist here? Or is there something else you're asking for?

@aralroca
Copy link
Owner

Wow @justincy you are right! This is already existing!! hah! Ok, perfect!

@aralroca
Copy link
Owner

This will be available on 0.11.0 release

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

No branches or pull requests

2 participants