Support passing path to localePath for easier resolving of dynamic routes
See original GitHub issueWhat 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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:6
Top GitHub Comments
Indeed. It’s #152
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.