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.

Inject route name without localization

See original GitHub issue

Is your feature request related to a problem? Please describe.

When you work with localized route path, the only way to get the original route name is to remove the "___xx" extra string from it. For exemple, I use vuex-router-sync to build my multi steps form. This way I can rely on the url to ensure the user didn’t cheat any step. Middleware + store help me to achieve that. It’s very annoying to split the localized route.name property each time. Plus I feel not confortable with this hacky method.

Describe the solution you’d like

If I could have a unique id injected in the route object it would solve this. For exemple, the raw name would do the trick. This way I can :

  • use it as a unique and useful id no matter the locale
  • use localPath({ name }) method to navigate to it

Describe alternatives you’ve considered

A working alternative is to retrieve this raw name by splitting the route name by "___"

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
existe-dejacommented, May 5, 2021

I blame the vuex-router-sync package to soon. I experienced problems with nested routes. The final fix to this is:

extendRoutes(routes) {
      for (const route of routes) {
        route.meta = {
          ...route.meta,
          immutableName: route.name
        };
        if (route.children) {
          for (const child of route.children) {
            child.meta = {
              ...child.meta,
              immutableName: child.name
            };
          }
        }
      }
    }
1reaction
rchlcommented, May 5, 2021

You have to return the routes. Or alternatively, modify the original route instead of creating a new list.

Also, I don’t think you can just add any property on the route object directly. Look at available properties at https://router.vuejs.org/api/#route-object-properties.

The meta object is likely a good choice in this case. Maybe try:

    extendRoutes(routes) {
        for (const route of routes) {
            route.meta = {
                immutableName: route.name,
            };
        }
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to support routes with and without language in URL in ...
Trying to set up localization for my current mvc project. I need to configure routing to support both urls: with and without language...
Read more >
Route name localization #233 - robisim74/angular-l10n - GitHub
route name is not localized, because in my opinion the language of the URIs is English, and not a mix of English and...
Read more >
Route - Angular
A configuration object that defines a single route. A set of routes are collected in a Routes array to define a Router configuration....
Read more >
Rails Internationalization (I18n) API - Ruby on Rails Guides
The process of "localization" means to provide translations and localized ... Every helper method dependent on url_for (e.g. helpers for named routes like ......
Read more >
Routing - Laravel - The PHP Framework For Web Artisans
Route parameters are injected into route callbacks / controllers based on their order - the names of the route callback / controller arguments...
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