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

How can I redirect translated url to the same page #712

Closed
Hayk1907 opened this issue May 15, 2020 · 11 comments · Fixed by #731
Closed

How can I redirect translated url to the same page #712

Hayk1907 opened this issue May 15, 2020 · 11 comments · Fixed by #731
Labels

Comments

@Hayk1907
Copy link

I want to translate url, but have an issue in ssr loading.
here is my configuration `

// nuxt.config.js
module.exports = {
...
modules: [
   [
      'nuxt-i18n',
      {
        seo: true,
        lazy: true,
        detectBrowserLanguage: {
          useCookie: true,
          cookieKey: 'i18n_redirected',
          alwaysRedirect: false,
          fallbackLocale: 'hy'
        },
        locales: [
          {
            name: 'English',
            code: 'en',
            iso: 'en-US',
            file: 'en.json'
          },
          {
            name: 'Հայերեն',
            code: 'hy',
            iso: 'hy-AM',
            file: 'hy.json'
          }
        ],
        langDir: 'locales/',
        defaultLocale: 'hy',
        parsePages: false,
         pages: {
           about: {
             en: '/about',
             hy: '/մեր֊մասին'
           },
       }
   ]
}

it works in client side when i link to localePath('about') . but when i refresh my page it cant find http://localhost:4000/մեր֊մասին

@rchl
Copy link
Collaborator

rchl commented May 15, 2020

Can you reproduce the same with pure Nuxt if you just name your route մեր֊մասին.vue?

@Hayk1907
Copy link
Author

my file structure `

pages/
├── about.vue

if i create մեր֊մասին․vue

pages/
├── about.vue
├── մեր֊մասին.vue

it will work . but is there a way to not create մեր֊մասին.vue . because if it works in client side why it cant work in ssr ?

@rchl
Copy link
Collaborator

rchl commented May 15, 2020

I'm trying to determine whether it's a problem with Nuxt or this module.
So you can't reproduce with nuxt-i18n disabled and route created manually?

@Hayk1907
Copy link
Author

I'm trying to determine whether it's a problem with Nuxt or this module.
So you can't reproduce with nuxt-i18n disabled and route created manually?

no

@rchl
Copy link
Collaborator

rchl commented May 25, 2020

There is actually a encodePaths option that you can set to false to fix it.
Check it here: https://nuxt-community.github.io/nuxt-i18n/options-reference.html

(It's not enabled by default because it's not compatible with some regexp path patterns but if you don't have any custom ones then you should be fine)

Let's keep this issue open for now. I'll check if it's possible to remove that option altogether while making all cases work.

EDIT: Actually it's the true (default) value that breaks the regexp. So I'm not sure anymore what this option is good for. I'll have to investigate.

@rchl rchl added bug 🐛 and removed question❓ labels May 25, 2020
rchl added a commit that referenced this issue May 25, 2020
This could be considered a breaking change but since I only know of it
breaking things rather than helping anything and there are no tests that
would prove me otherwise, I think it's safe to remove without releasing
a major version.

Also, Nuxt doesn't encode paths either so this change aligns with it.

Resolves #712
@rchl
Copy link
Collaborator

rchl commented May 25, 2020

I'll consider this a bug and fix with #731 by removing the encodePaths option and setting the default to false. See PR for reasoning.

@rchl
Copy link
Collaborator

rchl commented May 25, 2020

Paths encoding was fixing issue #7 but that one doesn't reproduce in latest Nuxt anymore so I'm even more confident in getting rid of encodePaths option.

@rchl rchl closed this as completed in #731 May 25, 2020
rchl added a commit that referenced this issue May 25, 2020
)

This could be considered a breaking change but since I only know of it
breaking things rather than helping anything and there are no tests that
would prove me otherwise, I think it's safe to remove without releasing
a major version.

Also, Nuxt doesn't encode paths either so this change aligns with it.

Resolves #712
@Hayk1907
Copy link
Author

Thanks it works

@moleCuleFFF
Copy link

This broke all my paths for languages such as Taiwanese, Japanese, Korean.

Please don't introduce MASSIVE breaking changes, to fix the issue of one user.

vue-router now expects all paths to be URIEncoded, can these be reverted and a correct solution for the problem found.

I'd rather not add URIEncode to every path on every class.

@rchl
Copy link
Collaborator

rchl commented Mar 25, 2021

The removal of encodePaths is almost a year old.

At the time the removal made sense as VueRouter didn't expect encoded paths.

If you have an issue now because VueRouter and Nuxt made changes then feel free to report an issue about it with proper reproduction steps and it will be fixed.

@moleCuleFFF
Copy link

WIll do.

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

Successfully merging a pull request may close this issue.

3 participants