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

Matched error when navigate using dynamic pages at same folder level #926

Closed
1 task done
ajmasia opened this issue Oct 12, 2020 · 8 comments
Closed
1 task done
Labels

Comments

@ajmasia
Copy link

ajmasia commented Oct 12, 2020

Version

nuxt-i18n: 6.15.1
nuxt: 2.14.0

Nuxt configuration

mode:

  • universal
  • [] spa

Nuxt-i18n configuration

i18n: {
    strategy: 'no_prefix',
    locales: [
      {
        code: 'es',
        iso: 'es-ES',
        file: 'es-ES.js',
        name: 'Español',
        domain: 'https://mydomain.com',
      },
      // {
      //   code: 'en',
      //   iso: 'en-US',
      //   file: 'en-US.js',
      //   name: 'English',
      //   domain: 'https://en.mydomain.com',
      // },
    ],
    vueI18n: {
      fallbackLocale: 'es',
    },
    defaultLocale: 'es',
    noPrefixDefaultLocale: true,
    parsePages: false,
    detectBrowserLanguage: false,
    seo: true,
    lazy: true,
    langDir: 'i18n/',
  },

Reproduction Link

https://codesandbox.io/s/suspicious-night-zbhxz?file=/pages/blog/index.vue

Steps to reproduce

I have two dynamic routes nested in the blog route. One of them shows the posts detail _slug.vue and the other shows a list of posts related to a category _category.vue. When I access to the detail of a post from the path _category.vue. instead of using the path blog-name keep using` blog-category '.

Both routes use the same PostCard component, that redirects to the _slug.vue page:

<NuxtLink
    :to="
      localePath({
        name: 'blog-slug',
        params: { slug: post.slug },
      })
    "
  >

But it doesn't redirect well. It does this using the path _category.vue:

Screenshot 2020-10-12 at 13 29 04

That is my current pages:

Screenshot 2020-10-12 at 13 31 03

What is Expected?

When navigating from http://localhost:8000/blog/page/1 to detail post, should navigate to http://localhost:8000/blog/post-slug using _slug.vueinstead of_category.vue`

What is actually happening?

Navigating always using _category.vue

Note: Using NuxtLink whiteout localePath, works fine!

@rchl
Copy link
Collaborator

rchl commented Oct 12, 2020

I'd ask you to make a repro project (either a repo or on codesanbox).

@ajmasia
Copy link
Author

ajmasia commented Oct 18, 2020

Hi @rchl, here you have a codesanbox example.

Using the localePath method, if you try to navigate to post detail, always use the category dynamic route.

If you do not use the localePath work fine in dev mode. In production, it doesn't work either.

what could be happening?

Thanks for your patient wait 😄

@rchl
Copy link
Collaborator

rchl commented Oct 18, 2020

I'm seeing this in my forked codesanbox where I haven't made any changes:

Screen Recording 2020-10-18 at 20 32 09

It looks to me like this is how it's supposed to work? Why I'm not seeing the issue?

@ajmasia
Copy link
Author

ajmasia commented Oct 18, 2020

If you navigate to a post from the blog or categories pages you should see the post detail through the _slug/index.vue component
Screenshot 2020-10-18 at 21 15 23

If you remove all localePath methods work fine!

I've updated the codesanbox repo: https://codesandbox.io/s/suspicious-night-zbhxz?file=/pages/blog/index.vue

@rchl
Copy link
Collaborator

rchl commented Oct 18, 2020

I can see that result in both cases...

Reloading the post page fails to show the extra detail though so I think you have a more fundamental problem.
Reloading the page triggers server-side rendering so you might be hiting problems related to that when doing client-side navigation.

@rchl
Copy link
Collaborator

rchl commented Oct 18, 2020

I mean, If you want to support server-side requests (which you should) then I think that this directory structure is not a proper solution since Vue Router won't know which route to pick based on the URL path itself. So you can make client-side navigations work but that is only half of the solution.

Anyways, localePath just generates an URL so it's functionally equivalent to specifying a route path to navigate to manually. You can just compare what you get by using localePath and if it's the same as the one you are saying is working, then it should work exactly the same. If it's different, then let me know what it is and I can then try to see what the issue issue is.

@ajmasia
Copy link
Author

ajmasia commented Oct 19, 2020

I updated the routes structure, and works fine!

Screenshot 2020-10-19 at 07 09 03

Now I can navigate to the post details using these path year/month/_slug, categories category and tags tag/_tag and blog pages page/_number to show the post list

Thanks for your help!

@rchl
Copy link
Collaborator

rchl commented Oct 19, 2020

It still looks to me like server side rendering won't be able to differentiate between category and year/month/slug routes but at least it's not a nuxt-i18n issue.

@rchl rchl closed this as completed Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants