question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support passing path to localePath for easier resolving of dynamic routes

See original GitHub issue

What problem does this feature solve?

localePath takes either string or object. String is expected to be route’s internal name. Object, with current implementation of localePath, will be passed to VueRouter’s resolve function but the name property will get ___[locale] appended to it.

The problem is that the object variant expects name to be set, otherwise it will create name value like undefined___[locale] and route will not match.

Given that it won’t work to pass an object with just {path: '/about'}, for dynamic routes like pages/_.vue, we must instead do an awkward localePath call like localePath({name: 'all', params: {0: 'about'}}) (haven’t really tested but I think it should work). This is IMO too cumbersome and what’s more, it requires knowledge of internal route’s name. It’s basically not user friendly.

What does the proposed changes look like?

It should be possible to call code below to get localized path to dynamic route

localePath({path: '/about'});

and let router figure out the path.

Note that with PREFIX_AND_DEFAULT mode, it should ideally only return path with locale prefix added, if resolving to non-default language OR when current route includes locale prefix.

So (with en being default locale):

  • /about >> localePath({path: ‘/about’}) >> /about
  • /en/about >> localePath({path: ‘/about’}) >> /en/about
  • /fr/about >> localePath({path: ‘/about’}) >> /fr/about
<div align="right">This feature request is available on Nuxt community (#c201)</div>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:6

github_iconTop GitHub Comments

2reactions
rchlcommented, Mar 14, 2019

I’d like to add that you must add your default locale last…

Indeed. It’s #152

0reactions
stale[bot]commented, Aug 12, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support passing path to localePath for easier resolving of ...
Given that it won't work to pass an object with just {path: '/about'} , for dynamic routes like pages/_.vue , we must instead...
Read more >
How to access route params: through a fully nuxt-i18n ...
vue file name to pick up route params? I wanted to have a button like so: <NuxtLink :to="localePath({ name: 'musicdb ...
Read more >
I18n Module - Nuxt
i18n features for your Nuxt project so you can easily add ... return the redirect path when resolving redirects with localePath (#1253) ...
Read more >
A Guide to Localizing with Nuxt.js
localePath () is provided by the nuxt-i18n library, which returns the localized path of the passed in route . <nuxt-link :to="localePath(' ...
Read more >
Options - i18n-module
syncRouteParams (default: true ) - Enables a setRouteParams mutation for using custom route names with dynamic routes. See more information in Dynamic route...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found