i18n icon indicating copy to clipboard operation
i18n copied to clipboard

Expose a way to get a route base

Open trandaison opened this issue 1 year ago • 9 comments

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

trandaison avatar Mar 01 '23 14:03 trandaison

I found this making my previous comment useless: I think this does what we want

https://v8.i18n.nuxtjs.org/api/composables/#useroutebasename

CaptainFalcon92 avatar Jul 04 '23 20:07 CaptainFalcon92

Can you give an example of what you mean exactly? I may be misunderstanding but your description sounds similar to the useLocaleRoute composable.

BobbieGoede avatar Aug 16 '23 09:08 BobbieGoede

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',
  ...
}

mojabyte avatar Sep 09 '23 13:09 mojabyte

@HassanMojab exactly!

A composable that return base route from localized route.

trandaison avatar Sep 12 '23 09:09 trandaison

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.

BobbieGoede avatar Sep 12 '23 10:09 BobbieGoede

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"
/>

mojabyte avatar Sep 25 '23 10:09 mojabyte