i18n
i18n copied to clipboard
Expose a way to get a route base
Describe the feature
We already have getRouteBaseName()
to get the base name of current (or given) route.
It would be useful if we have a similar getRouteBase(localizedRoute?: Route | RouteLocationNormalizedLoaded)
function to un-localize a route.
Additional information
- [ ] Would you be willing to help implement this feature?
- [ ] Could this feature be implemented as a module?
Final checks
- [X] Read the contribution guide (The contribution guideline of nuxt-modules/i18n is compliant with Nuxt too).
- [X] Check existing discussions and issues.
I found this making my previous comment useless: I think this does what we want
https://v8.i18n.nuxtjs.org/api/composables/#useroutebasename
Can you give an example of what you mean exactly? I may be misunderstanding but your description sounds similar to the useLocaleRoute composable.
for example, if the route object is something like this:
{
fullPath: '/es/about',
name: 'about___es',
path: '/es/about',
href: '/es/about',
...
}
then the getRouteBase
method should return the unlocalized version of the given route object, that is:
{
fullPath: '/about',
name: 'about',
path: '/about',
href: '/about',
...
}
@HassanMojab exactly!
A composable that return base route from localized route.
Could you give an example of a use case for this functionality? Technically there are many situations in which the unlocalized routes do not exist when using Nuxt I18n.
In my case, I use the ContectDoc
component from the nuxt-content
package and want to query the correct md file from the current path. Since I use locale-based routing, I need a way to get the base path from the locale path to pass the ContentDoc
:
<ContentDoc
:query="{ where: [{ _locale: locale }] }"
:path="routeBasePath"
/>